Zend 框架 + Doctrine1.2 项目结构具有更多模块

发布于 2024-12-12 21:15:41 字数 1176 浏览 6 评论 0原文

应用程序与 ZendFramework + Doctrine 1.2 的实现相结合已经有一段时间了,但现在他们第一次体验了更多模块的使用。我要求每个人都可以看到具有特定布局的默认模块和具有不同布局的管理模块。

到目前为止,在我的应用程序中,我一直使用以下结构:

/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

所以我的问题是:我的应用程序的结构应该如何执行所需的操作?

我尝试使用 zend 工具并查看我创建了命令的类型:

zf create module admin

当然,启动后

zf create project app

我注意到创建命令模块在 application 中创建了一个文件夹 modules 。 在modules中创建了admin,并在其中创建了controllersmodelsviews

因此,除了正确分离zf控制器和视图之外,还意味着模型。 但我的学说一方面创造了所有模型! :D

如何使用学说为每个模块创建的模板?

那么如何为管理模块分配新的布局呢?

对于聚会客人,您建议我离开当前使用的设施还是以默认的形式将其全部移动?

抱歉,如果我问了很多问题,也许太多了,但我真的很困惑!

谢谢

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?

I tried using zend tool and see what kind of structure I created the command:

zf create module admin

course after launching

zf create project app

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.

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!

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦毁影碎の 2024-12-19 21:15:41

经过详尽的文档后,我找到了正确的项目结构

/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 文件< /strong>

resources.frontController.plugins.auth = Plugin_Layout
resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts/"

上述插件会根据使用的模块在“layouts/scripts”中设置名为 module.phtml 的布局。


如何在模块内自动加载表单

将以下两行添加到您的 application.ini 文件

resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
resources.modules[] = ""

为每个模块创建一个 boostrap 文件。该文件名为 Bootstrap.php,应放置在模块目录的根目录中,类名称应为 {模块名称}_Boostrap。该引导文件将使 zend 框架自动将新的 forms 目录添加到自动加载器。

class Admin_Bootstrap extends Zend_Application_Module_Bootstrap {}

将表单类添加到 /forms 目录。登录表单的文件名为 Login.php,类名为 {模块名称}_Form_Login

class Admin_Form_Login extends Zend_Form

从同一模块内的控制器文件调用表单

$form = new Admin_Form_Login();

简单而有效! ;)

After a thorough documentation I've found the right project structure

/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

To view a different layout according to where you are module I used the following plugins:

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;
        }
    }
}

into Bootstrap.php file

 /**
 * @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;
}

into application.ini file

resources.frontController.plugins.auth = Plugin_Layout
resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts/"

the plugin described above according to the module in use will set the layout with the name of module.phtml within "layouts/scripts".


How to Autoload forms within a module

add the two below lines to your application.ini file

resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
resources.modules[] = ""

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 {}

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();

Simple and effective! ;)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文