Pass array from controller to view - Codeigniter

前端 未结 4 1293
感情败类
感情败类 2021-01-14 13:43

I tried to print the array in the controller, before passing it to a view and this is the output

Array ( [annunci] => Array ( [0] => stdClass Object (          


        
相关标签:
4条回答
  • 2021-01-14 14:24

    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
    
    0 讨论(0)
  • 2021-01-14 14:25
    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.

    0 讨论(0)
  • 2021-01-14 14:41
    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.

    0 讨论(0)
  • 2021-01-14 14:42

    (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);      
    }
    
    0 讨论(0)
提交回复
热议问题