Zend Framework + Doctrine1.2 项目结构,模块较多 [英] Zend Framework + Doctrine1.2 project structure with more modules
问题描述
应用程序加上 ZendFramework + Doctrine 1.2 的实现已有一段时间了,但现在他们有了使用更多模块的第一次体验.我要求每个人都可以看到具有特定布局的默认模块和具有不同布局的管理模块.
applications coupled with the realization ZendFramework + Doctrine 1.2 for some time, but now they have their first experience with the use of more modules. I requested a default module is visible to everyone with a certain layout and an admin module with a different layout.
到目前为止,在我的应用程序中,我一直使用以下结构:
So far in my applications I have always used the following structure:
/app
/application
/acls
/configs
/controllers
/forms
/layouts
/models --> models by doctrine
/generated --> base models by doctrine
/plugins
/views
/Bootstrap.php
/data
/doctrine
/data
/migrations
/schema
/schema.yml
/doctrine.php
/library
/public
/tests
所以我的问题是:我的应用程序的结构应该如何做所需的事情?
So my question is: how should the structure of my application to do what is required?
我尝试使用 zend 工具,看看我创建的命令是什么样的结构:
I tried using zend tool and see what kind of structure I created the command:
zf create module admin
启动后的课程
zf create project app
我注意到创建命令模块我在application
中创建了一个文件夹modules
.在 modules
中创建了 admin
并在其中创建了 controllers
、models
和 views
.
I noticed that the create command module I created a folder modules
in application
.
Into modules
created admin
and inside it has created controllers
, models
and views
.
所以zf除了正确分离意味着控制器和视图,还要模型.但我的学说一方面创造了所有的模型!:D
So in addition to separating means zf controller and view correctly, but also models. But my doctrine creates all the models on the one hand! :D
如何使用由学说为每个模块创建的模板?
How can I do to use templates created by doctrine for each module?
那我如何为管理模块分配一个新的布局?
Then how do I assign a new layout for the admin module?
对于派对客人,您建议我离开当前使用的设施还是以默认
的形式将其全部移动?
For the party guest you advise me to leave the facility that currently use or move it all in a form default
?
对不起,如果我问了很多问题,可能太多了,但我真的很困惑!
Sorry if I made a lot of questions, maybe too much, but I am really very confused about it!
谢谢
推荐答案
经过详尽的文档,我找到了正确的项目结构
/app
/application
/acls
/configs
application.ini
/layouts
/scripts
admin.phtml
default.phtml
/models --> models by doctrine
/generated --> base models by doctrine
/modules
/admin
/controllers
/forms
/view
/default
/controllers
/forms
/view
/plugins
/Bootstrap.php
/data
/doctrine
/data
/migrations
/schema
/schema.yml
/doctrine.php
/library
/public
/tests
要根据模块所在的位置查看不同的布局,我使用了以下插件:
class Plugin_Layout extends Zend_Controller_Plugin_Abstract
{
/**
* Called before an action is dispatched by Zend_Controller_Dispatcher.
*
* @param Zend_Controller_Request_Abstract $request
* @return void
*/
public function preDispatch(Zend_Controller_Request_Abstract $request)
{
$layout = Zend_Layout::getMvcInstance();
$module = $request->getModuleName();
switch ($module) {
case 'default':
$layout->setLayout('default');
break;
case 'admin':
$layout->setLayout('admin');
break;
default:
$layout->setLayout('default');
break;
}
}
}
进入 Bootstrap.php 文件
/**
* @return Zend_Application_Module_Autoloader
*/
protected function _initAutoload()
{
$autoloader = new Zend_Application_Module_Autoloader(array('namespace' => '', 'basePath' => APPLICATION_PATH));
$autoloader->addResourceType('plugin', 'plugins', 'Plugin');
return $autoloader;
}
进入application.ini文件
resources.frontController.plugins.auth = Plugin_Layout
resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts/"
上面描述的插件根据使用的模块会在layouts/scripts"中设置名为module.phtml的布局.
the plugin described above according to the module in use will set the layout with the name of module.phtml within "layouts/scripts".
将下面两行添加到您的 application.ini 文件中
add the two below lines to your application.ini file
resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
resources.modules[] = ""
为每个模块创建一个 boostrap 文件.名为 Bootstrap.php 的文件应放在模块目录的根目录中,类名应为 {module name}_Boostrap.这个引导文件将导致 Zend 框架自动将新的表单目录添加到自动加载器中.
Create a boostrap file for each module. The file, named Bootstrap.php, should be placed in the root of the module directory and the class name should be {module name}_Boostrap. This bootstrap file will cause zend framework to automatically add the new forms directory to the autoloader.
class Admin_Bootstrap extends Zend_Application_Module_Bootstrap {}
将表单类添加到/forms 目录.登录表单的文件名是 Login.php,类名是 {module name}_Form_Login
Add for form class to the /forms directory. A login form would have a filename of Login.php and a class name of {module name}_Form_Login
class Admin_Form_Login extends Zend_Form
从同一模块内的控制器文件调用您的表单
Call your form from a controller file from within the same module
$form = new Admin_Form_Login();
简单有效!;)
这篇关于Zend Framework + Doctrine1.2 项目结构,模块较多的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!