php - CodeIgniter HMVC data not passing from one function to another -
i passing function _homepage index not pass $data['articles'] it. can 1 me solve this? code updated
public function index(){ $mydata = array(); $this->mydata['menu'] = $this->mdl_page->get_nested(); $this->mydata['page'] = $this->mdl_page->get_by(array('slug' => (string) $this->uri->segment(1)), true); count($this->mydata['page']) || show_404(current_url()); //fetch page data $method = '_' . $this->mydata['page']->template; if (method_exists($this, $method)) { $this->$method(); } else { log_message('error', 'could not load template ' . $method .' in file ' . __file__ . ' @ line ' . __line__); show_error('could not load template ' . $method); } $this->mydata['subview'] = $data['page']->template; //dump($data); $this->load->view('_main_layout', $this->mydata); } private function _page(){ dump('welcome page template'); } private function _homepage(){ $this->load->model('admin/mdl_articles'); $this->db->limit(6); $this->mydata['articles'] = $this->mdl_articles->get(); //dump($data['articles']); } private function _news_archive(){ dump('welcome newspage template'); }
you should instead create private array property
private mydata = array();
in _homepage
method, contents should be:
private function _homepage(){ // ... // target class scope property $this->mydata['articles'] = $this->mdl_articles->get();
and change $data
variable $this->mydata
in index
method , pass view this:
$this->load->view('_main_layout', $this->mydata);
Comments
Post a Comment