Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
override model method
Hi,
I want to modify some methods of CategoriesModel in my plugin and I haven't been able to override them. I have override the assocciate caller controller methods but I have seen there are several places where there is a call to the model methods and it is easy to miss any of them. Even to maintain. Is there a way of make this change easy?
Thanks in advance.
0
Answers
very rarely is there cause to do this. I'm naturally a sceptical there is a need. what are you trying to do?
You could
grep is your friend.
I need a modification for my business for the queries to get categories and discussions filter by what we call domainId, which is store in the session. I want to put all this modifications in my new plugin. In fact, I have extended the model with new methods with the modified queries. The problem is that. The controllers that are using this models used the original method name and I want to use the new one. In order to force this I have overriden the controller methods but I'm sure in missing other calls to the model. In addition, there are methods in controllers that cannot be overriden. Let me show you and example:
method All of CategoriesController call to $CategoryModel->GetFull()
I want it to call CategoryModel->GetFullByDomain()
With categories, I want, as well, to update the permission table when a category is created.
My only solution is to overwrite the save method of the model.
The same thing with discussions. I have seen that $DiscussionModel->Get() is called from several controllers (p.e I have overriden the DiscussionsController Index method) and places.
How can achive this from my plugin?
Have a look for hooks in the core you should see
FireEvent
andEventArguments
and you can use hooks like sothis is just general pointer in the right direction you need to use your initiative. hope that helps
grep is your friend.
Thank you very much x00. Now, I'm modifying the CategoryModel_BeforeSaveCategory_Handler. The thing is that I have added a new column in the category table within the plugin like this:
Now I'm hooking to the BeforeSaveCategory_Handler to add this new field informed as well.
trying to add the new field to the FormPostValues array to save it as well but when I check the array in the CategoryModel after:
$this->FireEvent('BeforeSaveCategory');
The array does not contain the new element. Do you now if it is possible to do it? how?
For the moment, I have solved the problem by hooking to the controller:
But I still have the necessity to do it with the model for the case of discussions due to I call the save method in my own plugin code and I would like to intercept the discussion save at the point of:
Ah ok this is simple
grep is your friend.
If you think of event argument as supplying the hook with object data. They are one way, but if you pass by reference you can affect the underling objects. Arrays are not passed by reference unless you use &
grep is your friend.
Thanks x00. It did the trick.