Welcome Guest, Not a member yet? Register   Sign In
make codeigniter automatically insert/update created field and modified field like cake
#6

[eluser]vbsaltydog[/eluser]
[quote author="runrun" date="1327978678"]
So I make a model to check for created field (if exist), then insert the date. And I want to run this model automatically. But the problem is, technically, the model doesn't know what table to perform with.
[/quote]

Pass the table name to the model constructor at load time (or define it at the start of the model class as a class variable) , then have the model extend MY_Model, then put your update logic in the MY_Model constructor.

Code:
class MY_Model extends CI_Model
{

public function __construct()
{

// update logic here using the $this->table variable

}//End of function

}//End of class

class Whatever_Model extends MY_Model
{

public $table;

public function __construct($table)
{

$this->table = $table;

parent::__construct();

}//End of function

}//End of class


Messages In This Thread
make codeigniter automatically insert/update created field and modified field like cake - by El Forum - 01-30-2012, 09:34 PM



Theme © iAndrew 2016 - Forum software by © MyBB