[eluser]Unknown[/eluser]
Is there any one know how to use models to access the database, I wrote the following code, is there anything wrong about it.
Code:
<?php
class Blogmodel extends Model
{
var $title = '';
var $content = '';
var $date = '';
function _construct()
{
//Call the model constructor
parent::Model();
}
/*function Blogmodel()
{
$this->load->database();
}*/
function get_last_ten_entries()
{
$query = $this->db->get('entries',10);
return $query->result();
}
function insert_entry()
{
$this->title = $_POST['title'];
$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']));
}
}
The above gives the following error....
[error]
A PHP Error was encountered
Severity: Notice
Message: Undefined property: Blogmodel::$load
Filename: test/blogmodel.php
Line Number: 24
Fatal error: Call to a member function database() on a non-object in C:\wamp\www\CodeIgniter\system\application\models\test\blogmodel.php on line 24
[\error]
Plz help me...., actually I want to insert in database using models. If you have the code for inserting in database using model,view and controller, plz send it to me.