Php Zend Framework 2上的嵌套模块
我们可以在另一个模块中有多个模块吗 可能是类似的结构,如下所示:Php Zend Framework 2上的嵌套模块,php,zend-framework2,zend-autoloader,Php,Zend Framework2,Zend Autoloader,我们可以在另一个模块中有多个模块吗 可能是类似的结构,如下所示: /module /Application /module /SubApplication1 /SubApplication2 public function getAutoloaderConfig() { return array( 'Zend\Loader\ClassMapAutoloader' => array(
/module
/Application
/module
/SubApplication1
/SubApplication2
public function getAutoloaderConfig()
{
return array(
'Zend\Loader\ClassMapAutoloader' => array(
__DIR__ . '/autoload_classmap.php',
),
'Zend\Loader\StandardAutoloader' => array(
'namespaces' => array(
// This is the default namespace most probably the module dir name
__NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
// And this is for your custom namespace within the module
'SomeNamespace' => __DIR__ . '/src/' . 'SomeNamespace',
'OtherNamespace' => __DIR__ . '/src/' . 'OtherNamespace',
),
),
);
}
我正在寻找一个简单的例子或一篇有人知道这方面的文章。我在谷歌上搜索过以供参考,但似乎zf2的这一部分到目前为止还没有被探索过。在您的模块中很容易有多个名称空间。您只需要为Zend Autoloader提供配置。对于
Zend\Loader\StandardAutoloader
来说,可以在模块中设置配置,如下所示:
/module
/Application
/module
/SubApplication1
/SubApplication2
public function getAutoloaderConfig()
{
return array(
'Zend\Loader\ClassMapAutoloader' => array(
__DIR__ . '/autoload_classmap.php',
),
'Zend\Loader\StandardAutoloader' => array(
'namespaces' => array(
// This is the default namespace most probably the module dir name
__NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
// And this is for your custom namespace within the module
'SomeNamespace' => __DIR__ . '/src/' . 'SomeNamespace',
'OtherNamespace' => __DIR__ . '/src/' . 'OtherNamespace',
),
),
);
}
对于Zend\Loader\ClassMapAutoloader
来说,这是相同的概念。您只需将名称空间与类文件相匹配:
// file: ~/autoload_classmap.php
return array(
'SomeNamespace\Controller\SomeController' => __DIR__ . '/src/SomeNamespace/Controller/SomeController.php',
'OtherNamespace\Controller\OtherController' => __DIR__ . '/src/OtherNamespace/Controller/OtherController.php',
);
有些事要小心!确保子模块名称空间的名称不会与其他模块名称空间冲突
希望这有帮助:)
Stoyan在您的模块中很容易有多个名称空间。您只需要为Zend Autoloader提供配置。对于
Zend\Loader\StandardAutoloader
来说,可以在模块中设置配置,如下所示:
/module
/Application
/module
/SubApplication1
/SubApplication2
public function getAutoloaderConfig()
{
return array(
'Zend\Loader\ClassMapAutoloader' => array(
__DIR__ . '/autoload_classmap.php',
),
'Zend\Loader\StandardAutoloader' => array(
'namespaces' => array(
// This is the default namespace most probably the module dir name
__NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
// And this is for your custom namespace within the module
'SomeNamespace' => __DIR__ . '/src/' . 'SomeNamespace',
'OtherNamespace' => __DIR__ . '/src/' . 'OtherNamespace',
),
),
);
}
对于Zend\Loader\ClassMapAutoloader
来说,这是相同的概念。您只需将名称空间与类文件相匹配:
// file: ~/autoload_classmap.php
return array(
'SomeNamespace\Controller\SomeController' => __DIR__ . '/src/SomeNamespace/Controller/SomeController.php',
'OtherNamespace\Controller\OtherController' => __DIR__ . '/src/OtherNamespace/Controller/OtherController.php',
);
有些事要小心!确保子模块名称空间的名称不会与其他模块名称空间冲突
希望这有帮助:)
Stoyan有一种方法可以在一个模块中使用多个名称空间,非常简单。看看你是如何做到的。要做您愿意做的事情,我认为您必须使用
ModuleManager
进行大量工作。有一种方法可以在一个模块中使用多个名称空间,非常简单。看看你是如何做到的。要做您愿意做的事情,我认为您必须使用ModuleManager
做大量工作。