|
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错,头疼!大家看看是怎么回事呢?谢谢了 |
|