Multiple namespaces under same module in ZF2

前端 未结 2 2015
滥情空心
滥情空心 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:53

    You must let the StandardAutoloader know about your new namespace:

    public function getAutoloaderConfig()
    {
        return array(
            'Zend\Loader\ClassMapAutoloader' => array(
                __DIR__ . '/autoload_classmap.php',
            ),
            'Zend\Loader\StandardAutoloader' => array(
                'namespaces' => array(
                    // This is for the Account namespace
                    __NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
                    // And this is for the User namespace
                    'User'        => __DIR__ . '/src/' . 'User',
                ),
            ),
        );
    }
    

    In the module.config.php

    return array(
        'controllers' => array(
            'invokables' => array(
                'Account\Controller\Account' => 'Account\Controller\AccountController',
                // The key can be what ever you want, but the value must be a valid
                // class name. Your UserController lives in the User namespace,
                // not in Account
                'Account\Controller\User'    => 'User\Controller\UserController',
            ),
        ),
        /* ... */
    );
    

提交回复
热议问题