Codeigniter: Passing data from controller to view

后端 未结 13 2152
忘了有多久
忘了有多久 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:38

    You can create property $data = []; inside CI_Controller(path: system/core/Controller.php) and store all data to show in view. U can load common data like languages, menu, etc in CI_Controller. Also u can add special data for view in controller. (example: $this->data['message'] = "Hello world";) Finally, u can pass $this->data to view when load view (example: $this->load->view('view_name',$this->data);)

    I hope this will help you

提交回复
热议问题