一個模式,我無法從我的控制器加載模型無法加載在笨
這是控制器文件,article.php:
<?php
class Article extends CI_Controller {
function show($id) { //id'ye gore getir
$this->load->model('articles_model');
$parameter = $this->articles_model>getarticle($id);
$this->my_template->build('article_view', $parameter);
}
}
?>
這是模型文件,articles_model.php:
<?php
class Articles_model extends CI_Model {
function __construct()
{
// Call the Model constructor
parent::__construct();
}
function Getarticle($id) {
parent::Model();
$query = $this->db->get_where('articles', array('id' => $id));
$data['articles'] = $query->result();
return $data;
$query->free_result();
}
}
?>
只是補充,我甚至試圖從自動加載機加載它,仍然沒有機會,我認爲事情是錯誤的模型,或整個系統破裂了。
up:模型加載沒有問題,如果我把__construct函數中的回聲,它的工作原理,但是,我不能調用getarticle函數。 geez
UP:我做到了!根據http://grasshopperpebbles.com/codeigniter/codeigniter-call-to-a-member-function-on-a-non-object/
我用過 $ CI = & get_instance(); 和調用的函數 $ CI-> articles_model-> getarticle($ ID)和它調用的函數
它沒有工作,我一直在尋找了幾個小時的解決方案,我會感到羞恥,如果它實際上沒有=)。 誤差, 消息:未定義的屬性:第:: $ articles_model 文件名:控制器/ article.php --- 也, 的var_dump($這個 - > articles_model)返回NULL –