Zend Framework引导问题 [英] Zend Framework Bootstrap Issue

查看:87
本文介绍了Zend Framework引导问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一段时间以来,我一直在研究Zend Framework应用程序的新安装,但我不知道发生了什么.我有两个要使用的自定义动作帮助器,我想在引导程序中对其进行初始化.但似乎我的_init函数根本没有被调用.在启动应用程序的index.php中,我有:

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();

这是application.ini文件中的内容:

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"

我知道该应用程序在某种程度上可以正常工作,因为它使用的是我拥有的布局,并且我可以在控制器和视图中执行操作并将其输出到页面.我也知道,至少它正在查看Bootstrap文件,因为当我省略一个大括号时,我可能会发生PHP错误.

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.

这是我的Bootstrap文件的一部分:

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());
        }

有什么想法为什么会这样,或者看到我在配置中弄乱了什么?我看过数十本有关如何配置Zend的教程,似乎没有其他人遇到这个问题.

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.

推荐答案

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

You're not using the helper broker correctly. addPrefix() is used to add pluginloader prefix paths, not actual classes.

如果您想添加具体的助手(大概使用他们的派发钩子),则可以在Bootstrap类中放置类似的内容

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');

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

or using the strategy pattern (direct() method)

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


Doctrine Entity Manager

在您的Bootstrap类中执行类似的操作


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');

这篇关于Zend Framework引导问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆