Hello I am trying to instantiate a class controller of another class controller of a different module (created by me) that I am using but I can’t do it because I get the message:
Class ‘ZfCommons\Controller\MyAbstractActionController’ not found in
…..
and it is when I execute the command use ZfCommons\Controller\MyAbstractActionController;
The file that contents the class MyAbstractActionController the first command is:
namespace ZfCommons\Controller;
I guess I would have to do a require or include in PHP,but working with ZF2 I think maybe there is a more elegant way to do that.
How can I do it? Maybe I am using something wrong.
If you need to view more code I can copy and paste.
If you just want to get some service like object (e.g. some AuthService) you may register it as a service (you may have already done since you call
getAuthService()on the controller) and use the ServiceLocator to get it or – even better for unit testing – inject it via a factory to your controller. You may want to take a look at ZfcUser to see how it’s done.If you – for some reason – insist on using this hard-coded approach (which is really working against the framework) I think you just setup autoloading incorrectly or the ZfCommons module is not activated.
First
Check your application.config.php for activated modules. ZfCommons and Application need to be activated at least.
Second
Check ZfCommons’ Module.php for initializing of the autoloader:
This will initialize class autoloading for the namespace ZfCommons.
If your filenames map correctly to classes and interfaces according to PSR-0 it should work now.