加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

zend-framework – Zend Framework – 从bootstrap获取前端控制

发布时间:2020-12-13 13:37:11 所属栏目:PHP教程 来源:网络整理
导读:我正在尝试用这段代码将路由实现到我的bootstrap文件中; protected function _initRoutes(){ $router = $this-getResource('frontController')-getRouter(); $router-addRoute( 'profil',new Zend_Controller_Router_Route ( 'profil/:username',array ( 'co
我正在尝试用这段代码将路由实现到我的bootstrap文件中;
protected function _initRoutes()
{
    $router = $this->getResource('frontController')->getRouter();

    $router->addRoute(
        'profil',new Zend_Controller_Router_Route
        (
            'profil/:username',array
            (
                'controller' => 'users','action'    => 'profil'
            )
        )
    );
}

但它不起作用,因为我在’错误中的非对象上调用成员函数getRouter().

如何从bootstrap获取控制器?

我相信你的问题在于你在哪里打电话
$this->getResource('frontController')->getRouter()

FrontController资源尚未初始化.

我以这种方式调用了相同的方法(这在Zend Framework 2.0中不起作用,但现在可以工作):

Zend_Controller_Front::getInstance()->getRouter();

或者,您可以确保您的前端控制器已初始化为:

$this->bootstrap('FrontController');

$front =  $this->getResource('FrontController');

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读