Pass array from controller to view - Codeigniter

自古美人都是妖i 提交于 2019-12-01 10:54:21
public function get_annunci(){
    $query['annunci']=$this->user_model->annunci($this->email);        
    $this->load->view('main_view',$query);      
}

You're passing the array but you aren't passing annunci as a variable.

This is because you have not defined $annunci and made it available to the view. You need to load it to the view first by

Controller

$data['id'] = $yourArray;
$this->load->view('your_view_file', $data);

View

 <?php print_r($id); ?> //prints $yourArray
public function index()
    {
        $data=$this->model->viewBlog();
        $this->load->view('blog/index',['data'=>$data]);
    }

I hope this is work. if you handle n number of records use this method.

(Change $query to $query ['annunci']) OK, the $query is an array already, then just change the view file to 'tab_annunci_view'

So:

public function get_annunci(){
    $query=$this->user_model->annunci($this->email);        
    $this->load->view('tab_annunci_view',$query);      
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!