我正在尝试为zend框架项目创建一个Modular结构,我想要做的是创建一个看起来像这样的模块
docroot/
index.php
application/
default/
controllers/
IndexController.php
FooController.php
models/
views/
scripts/
index/
foo/
helpers/
filters/
blog/
controllers/
IndexController.php
models/
views/
scripts/
index/
helpers/
filters/
news/
controllers/
IndexController.php
ListController.php
models/
views/
scripts/
index/
list/
helpers/
filters/
阅读文档后我无法理解的是在哪里添加以下代码或者我应该重构/zendlibrary/Controller/front.php?
$front->setControllerDirectory(array(
'default' => '/path/to/application/controllers',
'blog' => '/path/to/application/blog/controllers'
));
OR
$front->addControllerDirectory('/path/to/application/news/controllers',
'news');
答案 0 :(得分:0)
首先,当我们这样做时,我们将模块放在 application / modules / 而不是application /
中在配置(application / configs / configuration.ini)中,你需要这样的东西:
[bootstrap]
Autoloadernamespaces[] = "Zend_"
Autoloadernamespaces[] = "default_"
Autoloadernamespaces[] = "blog_"
Autoloadernamespaces[] = "news_"
resources.frontController.moduleDirectory = APPLICATION_PATH "modules"
resources.frontController.defaultModule = "default"
resources.frontController.prefixDefaultModule = 1
resources.frontController.throwErrors = true
resources.modules[] = "default"
resources.modules[] = "blog"
resources.modules[] = "news"
resources.layout.layout = "layout"
resources.view.encoding = "UTF-8"
resources.view.basePath = APPLICATION_PATH "modules/default/views/"
可能会有更多内容,请告诉我这是否有帮助。
答案 1 :(得分:0)
向引导程序添加方法可能是最简单的方法:
protected function _initFrontController()
{
$front = Zend_Controller_Front::getInstance();
$front->setControllerDirectory(array(
'default' => APPLICATION_PATH.'/default/controllers',
'blog' => APPLICATION_PATH.'/blog/controllers'
));
return $front;
}
答案 2 :(得分:0)
您是否尝试过Zend Tool?
这很容易:
zf create module mymodule
详细了解Akrabat的帖子Bootstrapping modules in ZF。
您可以使用命令行在模块中轻松创建控制器,操作,模型和表单。该工具将为您生成一切。