zend modules models

2019-01-28 16:06发布

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

3条回答
狗以群分
2楼-- · 2019-01-28 16:34

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楼-- · 2019-01-28 16:35

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/.

查看更多
forever°为你锁心
4楼-- · 2019-01-28 16:38

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.

查看更多
登录 后发表回答