Multiple namespaces under same module in ZF2

前端 未结 2 2032
滥情空心
滥情空心 2021-01-05 18:04

I\'m having trouble configuring multiple namespaces/classes under same module. For example, I have a module called \"Account\", in which I\'d like to include all account rel

2条回答
  •  旧巷少年郎
    2021-01-05 18:57

    The StandardLoader needs to know where to find the classes. You can define it with an option called namespaces which is an array that contains absolute (or relative to the current script) paths. It should look like this:

    'Zend\Loader\StandardAutoloader' => array(
        'namespaces' => array(
            __NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__
        ) 
    ) 
    

    __NAMESPACE__ is the name of the module, and __DIR__ the absolute path to the Module.php script

    Check http://framework.zend.com/manual/2.0/en/modules/zend.loader.standard-autoloader.html

    The ClassMapAutoloader is used for performance: you define the class key and its exactly path to the file, instead of a folder which zf2 has to browse its contents doing filesystem operations (StandardLoader's way).

    Check http://framework.zend.com/manual/2.0/en/modules/zend.loader.class-map-autoloader.html

提交回复
热议问题