0
我傳遞函數_homepage索引,但它不傳遞$ data ['articles']。 任何人都可以幫我解決這個問題嗎? 此代碼更新CodeIgniter HMVC數據不從一個功能傳遞到另一個
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__ . ' at 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 from the 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 from the newspage template');
}
'$ data ['articles']'在方法'_homepage'的本地範圍內,除非返回'$ data'變量,否則''返回$ this-> Mdl_Articles-> get );'在你的索引方法中'$ data ['articles'] = $ this - > $ method();' ' –
@Rahil Wazir它正在加載整個方法。所以它必須被檢索。反正我嘗試你的建議,但它不起作用 – user3456989
Rahil我編輯這我不能這樣做你的方式,因爲我有其他方法給了我不同的結果。 – user3456989