Can I call the PHP MVC model another model?

I am currently adding a notification function to a website and need it to update its data whenever a user is added to a table. The way I think is right is to go through each of my controllers and whenever a model is called that changes this table, I will follow this up with a second call to the updateNotificationTable () function or something like that.

However, the site is quite large, and although I can follow all these controller calls with the update function, I can easily see that this is skipped for any future changes that interact with the table.

It seems that the most reliable way to do this would be to include a function inside the model itself, so that after it inserts or deletes a row from the table, it updates the notifications there. The problem is that the notification process retrieves data from a separate second model, which I have to load into the original model.

I do not believe that it should work this way, but an alternative could be a problem. In this case, would it be correct to load another model inside my model to handle notification updates?

edit: sample code

function addToTable(){
    //There 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);
}

doTheUpdate() model1 model2 , , $this- > other_model- > Insert_stuff(); updateNotifications(). , , .

, , . Notifications_Model model1 model2, doTheUpdate

+4

Source: https://habr.com/ru/post/1696072/


All Articles