duanlei1957 2011-03-31 19:04
浏览 42
已采纳

具有共同资源的Zend Framework模块

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

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.

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) 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!

  • 写回答

1条回答 默认 最新

  • dongmeiwei0226 2011-03-31 19:58
    关注

    Try this:

    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 points at the /application directory in your app
    • The form classes are named Application_Form_Something
    • The filenames of these classes are Something.php (case sensitive)

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#.net#的问题:End Function
  • ¥15 无法import pycausal
  • ¥15 VS2022创建MVC framework提示:预安装的程序包具有对缺少的注册表值的引用
  • ¥15 weditor无法连接模拟器Local server not started, start with?
  • ¥20 6-3 String类定义
  • ¥15 嵌入式--定时器使用
  • ¥20 51单片机学习中的问题
  • ¥30 Windows Server 2016利用兩張網卡處理兩個不同網絡
  • ¥15 Python中knn问题
  • ¥15 使用C#,asp.net读取Excel文件并保存到Oracle数据库