如何在代码点火器中将值从控制器传递到视图?

时间:2014-10-13 11:51:09

标签: php codeigniter codeigniter-2 php-5.3

控制器中的代码

  public function store_service_provider() {
            $get = file_get_contents('php://input');
            $json_decode = json_decode($get,true);
            foreach ($json_decode as $key => $value) {
                $data[$key] = $value;
            }        
            $data['role'] ='provider';  // assign role as provider
            $record = $this->serviceprovider_model->store_service_provider($data);                     
             if($record == '2'){
                $data['json'] = json_encode(array('flag' => 'false', 'message'=> 'you have account with this email id Thank you '));
                $this->load->view('jsonview', $data);
            } else {
            log_message("info",json_encode($record));
            $message['uname'] = '<html><h1>Hi '.$record['first_name']. " " .$record['last_name'].'</h1><br\>
            <h2><strong>Welcome to Look My Service.</strong></h2><br/>
            <h3>Your Username: '.$record['email'].'</h3><br\>
            <h2>To set your password
            <a href ="'.base_url().'serviceprovider#/change_password/'.$record['id'].'">Click here </a></h2><br\>
            <strong> Thank You </strong></html>';        
            $this->email->to($data['email']);
            $this->email->subject('Hall-book');
            $this->email->message(''.$message['uname'].'');
            $this->email->message($this->>view('hall_service/email_message',$record,true));
            $contact_number = $this->input->post("service_seeker_contact_number");        
            if(!$this->email->send()) {
                $data['json'] = json_encode(array('flag' => 'email_error', 'message'=> ' not correct login '));
                $this->load->view('jsonview', $data);
            }else{
                 $message = 'Welcome to Look My Service. Your Username  : '.$record['email'].' To set your password check you email Thank you.';
                  send($data['phone'], $message);
                echo json_encode(array('flag' => 'true', 'message'=> 'correct login '));
            }
        }
        }

在这里输入代码

 <html>
         <head>
              <title></title>
         </head>
    <body>
         <h1>sudarshan</h1>
         <?php foreach($record as $record):?>
              <span><?php echo $record; ?></span><br>
              <h1>Hi <?=$record->first_name?> " " <?=$record['last_name']?></h1><br/>
              <h2><strong>Welcome to Look My Service.</strong></h2><br/>
              <h3>Your Username: <?=$record->email?></h3><br/>
              <h2>To set your password
              <a href ="base_url()serviceprovider#/change_password/<?=$records['id']?>">Click here </a></h2><br/>
         <?php endforeach;?>
         <strong> Thank You </strong>
    </body>
    </html> 

我将$记录传递给视图,在控制器中我可以获取所有值,但是我无法获取$ record的值,如何解决此问题?如何禁用链接一旦它是点击

2 个答案:

答案 0 :(得分:3)

@aruna angadi

始终记住,当您将变量中的任何数据传递给控制器​​文件中的视图时,您无法在视图文件中获取相同的名称变量名称。

您只需向下一步即可获取数据。

实施例: -

如果你想传递

$data = array();

$data['record'] = $my_record_data;

$this->load->view('view_file_name',$data);

然后你将获得带有$ record变量的数据。

你可以像这样使用

<\ n> $record在您的视图文件中。

感谢

答案 1 :(得分:0)

在控制器中

添加代码

$ data = array();

$ data [&#39;记录&#39;] = $记录;

$这 - &GT;的电子邮件 - &gt;消息($这 - &GT;&gt;查看(&#39; hall_service / email_message&#39;,$数据,真));

而不是

$这 - &GT;的电子邮件 - &gt;消息($这 - &GT;&gt;查看(&#39; hall_service / email_message&#39;,$记录,真));