I am currently adding a notification feature to a website and need it to update it's data whenever a user is added to a table. The way I think is correct is to go through each of my controllers and whenever a call to the model is made that will change that table, I will follow that up with a second function call updateNotificationTable() or something like that.
The site is quite large however, and while I can make sure to follow all of these controller calls with an update function, I can easily see this being missed for any future changes that interact with the table.
It seems the most fool proof way to do this would be to include a function inside the model itself so that once it inserts or deletes a row from the table it would update the notifications there. The problem is that the notification process pulls data from a separate second model I would have to load up inside the starting model.
I don't believe it's supposed to work that way but the alternative would present problems too. In this instance would it be right to load another model inside my model to process the notification update?
edit: sample code
function addToTable(){
//There's probably a dozen or more functions like this scattered throughout various controllers, they all need to be followed by updateNotifications()
$this->other_model->Insert_stuff();
$this->updateNotifications();
}
function updateNotifications(){
$var1 = $this->model1->get_important_info();
$var2 = $this->model2->get_more();
$this->Notifications_Model->doTheUpdate($var1,$var2);
}
If I could instead take doTheUpdate() and have it directly call model1 and model2 to get it's required data then any future function that need to call $this->other_model->Insert_stuff(); will not need a follow up updateNotifications() call. If another programmer is working on it chances are good it won't happen.
There's probably a dozen or so controllers that I add this function to and call after various functions are executed. If Notifications_Model could directly call model1 and model2 then doTheUpdate