Codeigniter: Passing data from controller to view

后端 未结 13 2158
忘了有多久
忘了有多久 2020-11-27 06:57

I want to pass $data from the controller named poll to the results_view however I am getting an undefined variable error.

         


        
13条回答
  •  时光说笑
    2020-11-27 07:35

    Instead of

    $data = "hello";
    $this->load->view('results_view', $data);
    

    Do

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

    In your controller file and controller will send data having hello as string to results_view and in your view file you can simply access by

    echo $hello;
    

提交回复
热议问题