Welcome Guest, Not a member yet? Register   Sign In
Help with My_Model and extending it?
#1

Hi,

Been playing around with Jamie rumbelow's My_Model and find it really useful so far.

Just working with the 'observers' before_create and before_update. I've only been testing these observers with one model so far.

In that model I've got the following code:

PHP Code:
public $before_update = array( 'timestamps_for_update' );
 public 
$before_create = array( 'timestamps_for_create' );
 
 
   protected function timestamps_for_update($data)
 
   {
 
$data['updated_at'] = date('Y-m-d H:i:s');
 
$data['updated_by'] = $this->session->userdata('username'); 
 return 
$data;
 
   
 
    
    protected 
function timestamps_for_create($data)
 
   {
 
$data['created_at'] = $data['updated_at'] = date('Y-m-d H:i:s');
 
$data['created_by'] = $data['updated_by'] = $this->session->userdata('username'); 
 return 
$data;
 
   

Now, if I want to extend this functionality to all models in my app I don't want to write this code in every one ... so what's the best way tp proceed with this - use a 'Base' model to extend MY_Model and put the code in there and then extend all models from that?

Or is there another, better way?
Reply


Messages In This Thread
Help with My_Model and extending it? - by blackbulldog - 04-22-2015, 05:18 AM



Theme © iAndrew 2016 - Forum software by © MyBB