Zend 框架引导问题

发布于 2024-11-14 03:00:36 字数 1499 浏览 1 评论 0原文

我已经在新安装 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

〗斷ホ乔殘χμё〖 2024-11-21 03:00:36

您没有正确使用帮助代理。 addPrefix() 用于添加pluginloader前缀路径,而不是实际的类。

如果您想添加具体的帮助程序(大概要使用它们的调度挂钩),则在 Bootstrap 类中放置类似的内容

protected function _initActionHelpers()
{
    $helper = new My_Helper;
    Zend_Controller_Action_HelperBroker::addHelper($helper);
}

对于常规的运行时帮助程序,您可以轻松地在配置中添加前缀路径,例如,

resources.frontController.actionHelperPaths.ProEquipTrack_Controller_Action_Helper = "ProEquipTrack/Controller/Action/Helper"

这些路径将由代理自动加载在调用时,例如(控制器上下文)

$resourceInjector = $this->getHelper('ResourceInjector');
$em = $this->getHelper('Em');

或使用策略模式(direct() 方法)

$this->_helper->resourceInjector($arg1, $arg2 /*, etc */);

Doctrine Entity Manager

在 Bootstrap 类中执行类似的操作

protected function _initDoctrine()
{
    // initialise and create entity manager
    $em = // whatever

    return $em;
}

您现在可以使用此访问控制器中的实体管理器

$em = $this->getInvokeArg('bootstrap')
           ->getResource('doctrine');

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

protected function _initActionHelpers()
{
    $helper = new My_Helper;
    Zend_Controller_Action_HelperBroker::addHelper($helper);
}

For regular, runtime helpers, you can easily add prefix paths in your config, eg

resources.frontController.actionHelperPaths.ProEquipTrack_Controller_Action_Helper = "ProEquipTrack/Controller/Action/Helper"

These will be automatically loaded by the broker at call time, eg (controller context)

$resourceInjector = $this->getHelper('ResourceInjector');
$em = $this->getHelper('Em');

or using the strategy pattern (direct() method)

$this->_helper->resourceInjector($arg1, $arg2 /*, etc */);

Doctrine Entity Manager

Do something like this in your Bootstrap class

protected function _initDoctrine()
{
    // initialise and create entity manager
    $em = // whatever

    return $em;
}

You can now access the entity manager in your controllers using this

$em = $this->getInvokeArg('bootstrap')
           ->getResource('doctrine');
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文