I copied following code from official Codeigniter documentation.
class Blog_model extends CI_Model {
public $title;
public $content;
public $date;
public function get_last_ten_entries()
{
$query = $this->db->get('entries', 10);
return $query->result();
}
public function insert_entry()
{
$this->title = $_POST['title']; // please read the below note
$this->content = $_POST['content'];
$this->date = time();
$this->db->insert('entries', $this);
}
public function update_entry()
{
$this->title = $_POST['title'];
$this->content = $_POST['content'];
$this->date = time();
$this->db->update('entries', $this, array('id' => $_POST['id']));
}
}
Please check line 3-5 : There are three property called public $title; public $content;public $date;
.
What is the usage of them?
I asked this question because this codes works fine even when removing them.
I have tested it removing those there properties. Still I can call get_last_ten_entries()
, insert_entry()
, update_entry()
function from Controller without issue.