Reputation: 776
I want to override a controller inside a component
ie;
File path : components/com_test/controllers/test.php
how to override test.php ?
Upvotes: 2
Views: 1410
Reputation: 5615
As Pritesh mentioned, you can't*.
I can see a couple of ways to achieve the result:
You can create a new controller which extends your test.php controller, and invoke that instead; in order to achieve this, the controller must never use JPATH_COMPONENT and you'll have to override the view as well to point to the right component.
Add a special task to your view, and intercept it with a system plugin in OnAfterRoute()
. You won't be touching the original controller, but your plugin will fire before the original controller, so it can take action, manipulate input and output, and eventually avoid invoking the original controller altogether.
--
if editing the original controller could seem like an option, please disregard it: the original component will be updated from time to time and you'd be entering a maintenance nightmare.
Very often I have to achieve just this result. And 90% of the time I achieve this in a system plugin. In case of improvements, I contribute the code back to the original developer, who usually integrates the features in their next release. Don't forget to let the original developers know, you'll help improve their products and save yourself time.
Upvotes: 3
Reputation: 5154
we can not override the controller and model in joomla we will override only views of the component.
Upvotes: 2