开发者

Zend Framework Autoloading in 3 modules

开发者 https://www.devze.com 2022-12-22 13:52 出处:网络
I am new to ZF and I am writing in Zend Framework 1.10 . Here is my application directory structure. APPLICATION_PATH`

I am new to ZF and I am writing in Zend Framework 1.10 . Here is my application directory structure.

APPLICATION_PATH`
├─configs
 ├─layouts
 └─modules
    ├─admin
    │  ├─controllers
    │  ├─forms
    │  ├─models
    │  └─views
    │      ├─filters
    │      ├─helpers
    │      └─scripts
    │          ├─authentication
    │          ├─cars
    │          └─index
    └─default
        ├─controllers
        ├─forms
        │  └─admin
        ├─models
        │  └─DbTable
        ├─plugins
        └─views
            ├─helpers
            └─scripts
                ├─about
                ├─contact
                ├─error
                ├─index
                ├─insurance
                └─used-cars

I have 3 boots开发者_StackOverflow社区trap.php files in APPLICATION_PATH, /default/ and /admin,

i used AutoLoader to load models and forms

// APPLICATION_PATH/Bootstrap.php
$modelLoader = new Zend_Application_Module_Autoloader(array(
'namespace' => '', 'basePath' => APPLICATION_PATH . '/modules/default'));

The code above will load all models and forms automatically in modules/default, and now, I have a problem to call forms and models in /modules/admin/models and /modules/admin/forms in default module.

Any solutions to solve this problem? How should I name the class name in /modules/admin

Thanks.


each of your modules should have a module bootstrap.

<?php
class Admin_Bootstrap extends Zend_Application_Module_Bootstrap
{
}

the module bootstrap sets up default autoloaders for that module.

UPDATE IN RESPONSE TO COMMENT:

make sure your ini is set up to Bootstrap modules

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

Then make sure each of your modules has a bootstrap class (see above).


Try using Zend Tool - it will create all necessary paths and files for you and is a good way to get started with Zend.


All you should need to do is add another module autoloader to load the Admin module:

$adminLoader = new Zend_Application_Module_Autoloader(array(
    'namespace' => 'Admin', 'basePath' => APPLICATION_PATH . '/modules/admin'));

add it after the original module auotloader. You can then reference things in the Default module by just creating them.

$form = new Admin_Form_TheForm();
0

精彩评论

暂无评论...
验证码 换一张
取 消