Zend framework 1.8 推荐的插件注册方式? [英] Zend framework 1.8 recommended way to register a plugin?

查看:21
本文介绍了Zend framework 1.8 推荐的插件注册方式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Zend Framework 1.8 中,在 Zend Framework 1.8 中注册新插件的推荐方法是什么?

In Zend Framework 1.8, what is the recommended way to register a new plugin in Zend Framework 1.8?

<?php
/**
 * Enter description here...
 *
 */
class Wenbert_Controller_Plugin_CheckHasAccess extends Zend_Controller_Plugin_Abstract {

    /**
     * Enter description here...
     *
     * @param Zend_Controller_Request_Abstract $request
     */
    public function preDispatch(Zend_Controller_Request_Abstract $request) {
        echo 'This plugin is called...';
    }
}

我记得在 1.8 之前的版本中做过这样的事情:

I remember doing something like this in versions prior to 1.8:

require_once 'Wenbert/Controller/Plugin/CheckHasAccess.php';
$frontController = Zend_Controller_Front::getInstance();
$frontController->registerPlugin(new Wenbert_Controller_Plugin_CheckHasAccess());

在 ZF 1.8 中最好/推荐的方法是什么?

What would be the best / recommended way to do it in ZF 1.8?

提前致谢!

-温伯特

推荐答案

我假设您指的是 Zend_Application 做事方式.你上面提到的方式绝对没有问题.也就是说,您可以指定在 application.ini 中加载哪些插件,如下所示:

I'm assuming you mean the Zend_Application way of doing things. There's absolutely nothing wrong with the way you mentioned above. That said, you can specify which plugins to load in your application.ini, like so:

resources.frontController.plugins.foo = "My_Plugin_Foo"
resources.frontController.plugins.bar = "My_Plugin_Bar"

我知道这种方法的唯一缺点是您无法控制插件的优先级(在插件堆栈中的位置)……但对于大多数(几乎所有情况)来说,这无关紧要.

The only draw back that I am aware of with this approach, is that you cannot control the priority (location in the plugin stack) of the plugin... but for most (almost all cases) that shouldn't matter.

这篇关于Zend framework 1.8 推荐的插件注册方式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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