值无法在codeigniter中从控制器传递到视图

时间:2016-09-07 09:47:39

标签: php codeigniter

我的控制器代码是

路径:application / views / admin enter image description here

控制器代码

public function email()
{
    $data['page'] = lang('settings');
    $data['load_setting'] = 'email_settings';
    $data['title'] = lang('email_settings'); //Page title              
    $data['subview'] = $this->load->view('admin/settings/settings', $data, TRUE);
    $this->load->view('admin/_layout_main', $data); //page load     
    $qry = $this->db->query("SELECT * FROM `tbl_email_setting` WHERE user_id='".$this->session->userdata('user_id')."'");
    $data1['email_values'] = $qry->result_array();      
    $this->load->view('admin/settings/email_settings', $data1);
}

我在视图中将$data1传递给email_settings.php个文件。 当我尝试在$email_values中打印views/admin/settings/email_settings.php时,错误将在下面显示

  

遇到PHP错误     严重性:注意     消息:未定义的变量:email_values     文件名:settings / email_settings.php     行号:109

1 个答案:

答案 0 :(得分:1)

根据您的意见:

这是我打印的视图代码<?php echo 'email server type:-----';print_r($data1['email_values']);?> - R V Informatics Pvt Ltd

您只需将视图文件中的数据打印为:

<?php 
echo 'email server type:-----';
print_r($email_values);
?>

建议/附注:

我建议您将此视图存储在变量中:

$this->load->view('admin/_layout_main', $data); //page load     

同样如此:

$data['subview'] = $this->load->view('admin/settings/settings', $data, TRUE);