codeigniter-base-model
codeigniter-base-model copied to clipboard
A question with Callbacks/Observers
after created a feedback, Send a message, But that does not work, I write code like this
class Feedback_model extends MY_Model { public $after_create = array('add_message');
protected function add_message($data)
{
$msg = array('subject' => 'You have message from '.$data['name']);
$this->db->insert('messages', $msg);
return $data;
}
}
Sorry, what does "does not work" mean? Are you getting any errors?
Thank you for your reply, I can't get value of $data['name']
DO you have a better way to get this work?
I believe the after_create trigger only returns the insert id.
So, if it's returning the newly inserted ID, you could do this:
$feedback = $this->get($data);
$feedback->name;
Thank you very much ,that's works now
sorry, i just want to post is :
class Feedback_model extends MY_Model { public $after_create = array('add_message');
protected function add_message($data)
{
$msg = array(......);
$this->message_model->add_msg($msg);
}
}
Yeah, of course. It's a normal model, just load it like usual!