Zend 模块中的自动加载器找不到表单?
我已经厌倦了 Zend 的自动加载器。
我正在尝试从模块结构中的 PasswordController
加载 EditPassword
,如下所示。
application.ini
includePaths.library = APPLICATION_PATH "/../library"
bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
bootstrap.class = "Bootstrap"
appnamespace = "Application"
resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"
resources.frontController.params.displayExceptions = 0
resources.frontController.baseUrl = "/"
resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts/"
phpSettings.date.timezone = "Europe/London"
Bootstrap.php:
public function init() {
$config = new Zend_Config_Ini(APPLICATION_PATH . '/configs/application.ini', APPLICATION_ENV);
$baseUrl = $config->baseHttp;
define('BASE_URL', $baseUrl);
}
protected function _initAutoload() {
$autoLoader = Zend_Loader_Autoloader::getInstance();
$autoLoader->registerNamespace('App_');
//
$moduleLoader = new Zend_Application_Module_Autoloader(array(
'namespace' => '',
'basePath' => APPLICATION_PATH . 'modules/account',
'resourceTypes' => array(
'form' => array(
'path' => 'forms',
'namespace' => 'Form'))));
$autoLoader->pushAutoloader($moduleLoader);
//
return $autoLoader;
}
我正在控制器中加载表单,如下所示:
$form = new Account_Form_EditPassword();
$this->view->form = $form;
错误本身是:
Fatal error: Class 'Account_Form_EditPassword' not found in
Z:\dat\docs\workspace\metamusic\application\modules\account\controllers\PasswordController.php
on line 7
我做错了什么? Zend 中的其他所有内容似乎都运行相当合理的默认值 - 我是否真的必须声明每个模块的所有表单/模型/viewhelpers 路径,因为它们遵循默认的 Zend 结构,并且在默认模块目录中?
I'm getting pretty fed up with Zend's autoloader.
I'm trying to load EditPassword
from within PasswordController
in the module structure as shown below.
application.ini
includePaths.library = APPLICATION_PATH "/../library"
bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
bootstrap.class = "Bootstrap"
appnamespace = "Application"
resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"
resources.frontController.params.displayExceptions = 0
resources.frontController.baseUrl = "/"
resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts/"
phpSettings.date.timezone = "Europe/London"
Bootstrap.php:
public function init() {
$config = new Zend_Config_Ini(APPLICATION_PATH . '/configs/application.ini', APPLICATION_ENV);
$baseUrl = $config->baseHttp;
define('BASE_URL', $baseUrl);
}
protected function _initAutoload() {
$autoLoader = Zend_Loader_Autoloader::getInstance();
$autoLoader->registerNamespace('App_');
//
$moduleLoader = new Zend_Application_Module_Autoloader(array(
'namespace' => '',
'basePath' => APPLICATION_PATH . 'modules/account',
'resourceTypes' => array(
'form' => array(
'path' => 'forms',
'namespace' => 'Form'))));
$autoLoader->pushAutoloader($moduleLoader);
//
return $autoLoader;
}
I'm loading the form in the controller like this:
$form = new Account_Form_EditPassword();
$this->view->form = $form;
The error itself is:
Fatal error: Class 'Account_Form_EditPassword' not found in
Z:\dat\docs\workspace\metamusic\application\modules\account\controllers\PasswordController.php
on line 7
What am I doing wrong? Everything else in Zend seems to run off fairly sane defaults - do I really have to declare all the paths to forms/models/viewhelpers for each module, given that they're following the default Zend structure, and in the default modules directory?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我将从应用程序 Bootstrap 中删除所有模块自动加载代码,然后在
application/modules/account/Bootstrap.php
中实现一个空模块引导程序:然后在
application/configs/application.ini< /code>,添加以下内容:
这里的想法是
Zend_Application_Module_Bootstrap
自动注册一个带有一堆常见路径/命名空间映射的资源自动加载器,包括您正在使用的表单的映射 使用。I would remove all the module autoloading code from the app Bootstrap and then implement an empty module bootstrap in
application/modules/account/Bootstrap.php
:Then in
application/configs/application.ini
, add the following:The idea here is that
Zend_Application_Module_Bootstrap
automatically registers a resource autoloader with bunch of common path/namespace mappings, including the one for forms that you are using.在 Bootstrap.php 中
'basePath' =>应用程序路径。 'modules/acount'
应为:
'basePath' =>应用程序路径。 'modules/account'
其他一切看起来都不错
In Bootstrap.php
'basePath' => APPLICATION_PATH . 'modules/acount'
Should be:
'basePath' => APPLICATION_PATH . 'modules/account'
Everything else looks ok
如果这是从您的实际配置复制/粘贴,那么您在
'modules/acount'
中存在拼写错误。根据您的 ZF 版本,您甚至不需要引导程序中的自动加载器。您可以将其删除。 ini 中的以下内容具有相同的作用。
If this a copy/paste from your actual config then you have a typo in
'modules/acount'
Depending on your ZF version you don't even need the autoloader in the bootstrap. You can remove it. The following in your ini does the same.