Domanda

I'm trying to figure out if I can use ZF2's Loader/Autoloader to "auto discover" modules and classes. I am not using ZF2 in its native MVC framework structure, but rather as a library.

Current, I have the following structure:

/Application
   /Application
   /Module
     /MyCustomModule
       /Controller
          MyCustomModuleController.php
       /Model
       /View
   /Vendor
     /zendframework
     /randomLibrary

In my Autoloader setup, I have the following:

array(
    'Zend\Loader\StandardAutoloader' => array(
        'namespaces' => array(
             'Zend' => $filedir . '/Application/Vendor/Zend/',
     ),
     'fallback_autoloader' => $fallback,
      ),
);

Is there a way that I can get the loader to auto discover the module and class: MyCustomModuleController which has a FQN of MyCustomModule\Controller\MyCustomModuleController with a resource location path of: ./Application/Module/MyCustomModule/Controller/MyCustomerModuleConstroller.php?

È stato utile?

Soluzione

Have you tried adding a line to the autoloader setup file ? I mean, something like this:

array(
    'Zend\Loader\StandardAutoloader' => array(
        'namespaces' => array(
            'Zend' => $filedir . '/Application/Vendor/Zend/',
            'MyCustomModule' => $filedir .'/Module/MyCustomModule/',
        ),
        'fallback_autoloader' => $fallback,
    ),
);
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top