如何解决此错误 - 严重性:通知消息:未定义的变量:表

时间:2017-11-15 16:17:46

标签: php html codeigniter

我的控制器是:

public function index() {
    if ($this->session->userdata ( 'logged_in' )) {
        $condition = array(
            'qes_status'=>'Y'
        );
        $data = array();
        $data['orders'] = $this->common_model->get_all( 'qes_order');
        $id=$this->session->userdata( 'user_id' );
        $table['quote'] = $this->common_model->get_count_of($id);
        $this->load->view ( 'layouts/inc_header' );
        $this->load->view ( 'layouts/dashboard',$data,$table );
        $this->load->view ( 'layouts/inc_footer' );
    } else {
        redirect ( 'vendor', 'refresh' );
    }
}

我的视图是:

<div class="dash-box-body">
    <span class="dash-box-count"><?php echo $table?></span>
    <span class="dash-box-title">Quotes Awaited</span>
</div>

我的型号是:

public function get_count_of($id){
    $this->db->select ( '*' );
    $this->db->from ('qes_quote');
    $this->db->where ('qes_vendor_id',$id );
    $query = $this->db->get ();
    return $query->num_rows ();
}

这是我的代码。 错误是:

  

严重性:通知消息:未定义的变量:table。

请帮我解决这个问题。

1 个答案:

答案 0 :(得分:0)

您需要将$table传递给您的观点:

$data['table'] = $table;
$this->load->view('view', $data); 

因为看起来$table是一个数组,在你的视图中:

<span class="dash-box-count"><?php echo $table['quote'];?></span>