具有公共资源的 Zend 框架模块 [英] Zend Framework Modules with common resources

查看:21
本文介绍了具有公共资源的 Zend 框架模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在弄清楚如何拥有模块化目录结构时遇到了很多麻烦,并且能够加载要跨模块共享的资源.即,

I'm having a lot of trouble figuring out how we can have a modular directory structure, with the ability to load resources that are to be shared across modules. I.e.,

application
--- /forms
--- /models
--- /modules
------/module1/
---------/models
------/module2/
---------/models

现在,我要做的是从模块内加载/application/forms 中的表单.我尝试过的所有方法都导致这些类没有被加载.

Now, what I'm trying to do is load forms in /application/forms from within the modules. Everything I've tried results in these classes to not being loaded.

我试过:1) 让 Zend 尝试自动解决它.2) 在主引导程序中为应用程序路径和模块指定所有路径.即,

I've tried: 1) Letting Zend try and figure it out automagically. 2) Specifying all the paths in the main bootstrap for the application path as well as the modules. I.e.,

protected function _initAutoload()
{
    $front = $this->bootstrap("frontController")->frontController;
    $modules = $front->getControllerDirectory();
    $default = $front->getDefaultModule();

    $moduleloader = new Zend_Application_Module_Autoloader(array(
        'namespace' => 'Application',
        'basePath'  => APPLICATION_PATH
    ));

    foreach (array_keys($modules) as $module) {
        $moduleloader = new Zend_Application_Module_Autoloader(array(
            'namespace' => ucfirst(strtolower($module)),
            'basePath'  => $front->getModuleDirectory($module))
        );
    }
}

3) 多次把我的头砸在我的桌子上.

3) Smashing my head on my desk many times.

.. 是的,我意识到我不需要模块的循环,因为我在每个模块目录中都有空白的引导程序.

.. and yes, I realize I do not need that loop for modules, as I have blank bootstraps in each module directory.

欢迎提出任何建议.谢谢!

Any suggestions are welcome. Thanks!

推荐答案

试试这个:

protected function _initAutoload()
{
    $autoloader = new Zend_Application_Autoloader_Resource(array(
        'namespace' => 'Application',
        'basePath'  => APPLICATION_PATH,
        'resourceTypes' => array(
            'form' => array(
                'path' => 'forms/',
                'namespace' => 'Form'
            )
        )
    ));

    return $autoloader;
}

您不需要模块部分,正如您似乎已经知道的那样.根据需要添加其他资源类型.

you don't need the module part, as you already seem to know. Add other resource types as required.

由于这与您已有的非常接近,因此可能存在另一个问题.以上应该假设:

Since this is very close to what you have already, there may be another issue. The above should work assuming that:

  • APPLICATION_PATH 指向您应用中的/application 目录
  • 表单类被命名为 Application_Form_Something
  • 这些类的文件名是Something.php(区分大小写)

例如如果您有联系表单,您可以调用 Application_Form_Contact 类,它位于 application/forms/Contact.php.

e.g. if you have a contact form, you might call the class Application_Form_Contact and this would live at application/forms/Contact.php.

如果您仍有问题,请提供一个找不到的表单类的示例,以及您调用它的方式和位置.

If you're still having issues, please include an example of a form class that isn't being found, along with how and where you are calling it from.

这篇关于具有公共资源的 Zend 框架模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆