Zend 框架引导问题
我已经在新安装 Zend Framework 应用程序一段时间了,但我不知道发生了什么。我有两个想要使用的自定义操作助手,并且我想在引导程序中初始化它们。但似乎我的 _init 函数根本没有被调用。在启动应用程序的 index.php 中,我有:
require('Zend/Application.php');
$app = new Zend_Application(APPLICATION_ENV, APPLICATION_PATH
.'/configs/application.ini');
$app->bootstrap()->run();
这是我在 application.ini 文件中的内容:
[production]
appnamespace = "Application_Name"
includePaths.library = APPLICATION_PATH "/../library"
bootstrap.path = "/home/user/website/includes/library/Application_Name/Resource/Bootstrap.php"
bootstrap.class = "Bootstrap"
resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"
resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts"
resources.view[] =
autoloaderNamespaces[] = "Application_Name"
pluginPaths.Application_Name_Resource = "Application_Name/Resource"
我知道该应用程序在某种程度上可以工作,因为它使用的是我拥有的布局,我可以在控制器和视图中执行操作,将其输出到页面。我还知道它至少会查看 Bootstrap 文件,因为当我省略结束大括号时,可能会发生 PHP 错误。
这是我的 Bootstrap 文件的一部分:
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
public function _init()
{
Zend_Controller_Action_HelperBroker::addPrefix(new Application_Name_Controller_Action_Helper_ResourceInjector());
Zend_Controller_Action_HelperBroker::addPrefix(new Application_Name_Controller_Action_Helper_Em());
}
有什么想法为什么会出现这种情况或看到我在配置中弄乱的东西吗?我看过几十个关于如何配置 Zend 的教程,似乎没有人遇到这个问题。
I have been working on a new installation of a Zend Framework application for a while now, and I cannot figure out what's going on. I have two custom action helpers I would like to use and I would like to initialize those in the bootstrap. But it seems as though my _init functions are not being called at all. In the index.php that starts the application I have:
require('Zend/Application.php');
$app = new Zend_Application(APPLICATION_ENV, APPLICATION_PATH
.'/configs/application.ini');
$app->bootstrap()->run();
Here's what I have in the application.ini file:
[production]
appnamespace = "Application_Name"
includePaths.library = APPLICATION_PATH "/../library"
bootstrap.path = "/home/user/website/includes/library/Application_Name/Resource/Bootstrap.php"
bootstrap.class = "Bootstrap"
resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"
resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts"
resources.view[] =
autoloaderNamespaces[] = "Application_Name"
pluginPaths.Application_Name_Resource = "Application_Name/Resource"
I know the application is somewhat working because it is using a layout that I have and I can do things in the controllers and views and have it output to the page. I also know that it is at least looking at the Bootstrap file because I can make a PHP error happen when I leave out an end curly brace.
Here's a portion of my Bootstrap file:
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
public function _init()
{
Zend_Controller_Action_HelperBroker::addPrefix(new Application_Name_Controller_Action_Helper_ResourceInjector());
Zend_Controller_Action_HelperBroker::addPrefix(new Application_Name_Controller_Action_Helper_Em());
}
Any ideas why this would be or see something that I've messed up in my configuration? I've looked at tens of tutorials on how to configure Zend, and no one else seems to have this problem.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您没有正确使用帮助代理。
addPrefix()
用于添加pluginloader前缀路径,而不是实际的类。如果您想添加具体的帮助程序(大概要使用它们的调度挂钩),则在 Bootstrap 类中放置类似的内容
对于常规的运行时帮助程序,您可以轻松地在配置中添加前缀路径,例如,
这些路径将由代理自动加载在调用时,例如(控制器上下文)
或使用策略模式(
direct()
方法)Doctrine Entity Manager
在 Bootstrap 类中执行类似的操作
您现在可以使用此访问控制器中的实体管理器
You're not using the helper broker correctly.
addPrefix()
is used to add pluginloader prefix paths, not actual classes.If you want to add concrete helpers (to use their dispatch hooks presumably), then place something like this in your Bootstrap class
For regular, runtime helpers, you can easily add prefix paths in your config, eg
These will be automatically loaded by the broker at call time, eg (controller context)
or using the strategy pattern (
direct()
method)Doctrine Entity Manager
Do something like this in your Bootstrap class
You can now access the entity manager in your controllers using this