为什么我的一直报错?
class Blog_model extends Model {var $title = '';
var $content = '';
var $date = '';
function Blog_model()
{
// Call the Model constructor
parent::Model();
}
function get_last_ten_entries()
{
$query = $this->db->get('blogs', 10);
return $query->result();
}
function insert_entry()
{
$this->title = $_POST['title']; // please read the below note
$this->content = $_POST['content'];
$this->date = time();
$this->db->insert('entries', $this);
}
function update_entry()
{
$this->title = $_POST['title'];
$this->content = $_POST['content'];
$this->date = time();
$this->db->update('entries', $this, array('id' => $_POST['id']));
}
}
这是手册里的一个Model,我写了一个controller
class Lobby extends Controller
{
function Lobby(){
parent::Controller();
}
//default function
function index()
{
$this->load->model('Blog_model');
$this->Blog_model->get_last_ten_entries();
$this->load->view('lobby');
}
}
可是总是报错,说没有$Blog_model::$db这个属性,还有时是500错,头疼!大家看看是怎么回事呢?谢谢了 本帖最后由 qilihong 于 2009-11-6 16:25 编辑
知道怎么回事了,没有加载数据库类:(
$this->load->database()就ok了
一般把这个加到config/autoload.php里面就行了,不用每次都加载
页:
[1]