zend modules models

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-29 09:08:30

问题


My application setup with 2 modules admin and default I test the controller which works fine on modules

but the models doesnt work

I created a model application\modules\admin\models\User.php

<?php

class Admin_Model_User{
}

inside the controller

$user = new Admin_Model_User();

Fatal error: Class 'Admin_Model_User' not found


回答1:


Essentially, you need 2 lines in the application.ini file;

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

Then, for each module, you need a module bootstrap file:

File: myproject/application/modules/{modulename}/Bootstrap.php

<?php

class {Modulename}_Bootstrap extends Zend_Application_Module_Bootstrap
{
}

(Yes, it is an empty class.)

Further details are at http://akrabat.com/zend-framework/bootstrapping-modules-in-zf-1-8/.




回答2:


Configure an autoloader so that the framework can map your class prefix Admin_Model to the corresponding source path. This is not done automatically.

I suggest reading the part on models of the Zend Framework Quickstart, which explains in detail how to do this.




回答3:


Are you using an autoloader?

If you do you should change the class name (or path) to reflect the path (or class name)

Models <> Model

You should have

Admin_Model_User in admin/model/user.php

or

Admin_Models_User in admin/models/user.php.



来源:https://stackoverflow.com/questions/1836447/zend-modules-models

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!