What is the best way of calling an action of another controller?
I am thinking in different options:
- Using forward plugin
- Setting the second controller as a dependency in the first controller
I think the first option will work but I would like to know if the second one has sense. In that case,
- How can I get the controller dependency?
I have tried to get it using the Service Manager but it isn't there. I have tried creating a Factory for the controller and get the another controller from the Controller Manager which is passed as an argument to the createService method when you implement the FactoryInterface. But it says that no controller is there. Exists a different locator from controllers than can be used in the same way as the Service Locator?
- The controller which has the role of dependency and will be called has to extends or implements any particular class or interface?
To forward with parameters :
I have found how to get ControllerManager in a controller:
I would say that using the
forward
plugin is the ZF2 way to do it. This other solution that you propose sounds very complicated and might get you in all sorts of unsuspected trouble with dito bugs.Or is there a reasonable argument why using this
forward
plugin is not what you want?I actually don't understand why you can't get your other controller from your
ControllerManager
. Are you sure it is registered and that you use the correct name to get it?