php - Codeigniter Why I can't load view from MY_Controller -


i want every controller have method _render_page, loads master template , passes data object.

my home controller class looks this:

class home extends my_controller {      function __construct() {         parent::__construct();     }      public function index() {         $data['title'] = "site title";         $data['the_view'] = 'welcome_message';         $this->_render_page($this->layout, $data);         //$this->load->view($this->layout, $data);  //this works ok..     } } 

my_controller class:

class my_controller extends ci_controller {      public $layout;     public $viewdata;      public function __construct() {         parent::__construct();         $this->layout = 'layout/master_template';         $this->viewdata = null;     }      public function _render_page($view, $data=null, $render=false) {         $this->viewdata = $data;         $this->viewdata['the_view'] = $view;         if($this->ion_auth->logged_in()) {             $user_obj = $this->ion_auth->user()->row();             $usr_data['username'] = $user_obj->username;             $user_obj = null;             $this->viewdata['usr_data'] = $usr_data;         }         $this->load->view($this->layout, $this->viewdata);  //the code crashes here     } } 

when browse home controller nothing, white screen no errors...

found solution: i'm calling _render_page in wrong way. instead of this:

$this->_render_page($this->layout, $data); 

i should call this:

$this->_render_page('welcome_message', $data); 

of course, that's function - load master page , pass view name member of $data, master page know view load.


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -