dqnz43863 2014-04-26 20:02
浏览 58

Zend Framework检查控制器是否存在

I'm looking for a solution to the problem I mentioned in the title.

I have ROUTER and I have an order I check whether the controller exists or not and I can not find a solution.

I did something like this

class Plugin_Router extends Zend_Controller_Plugin_Abstract {

    public function routeStartup (Zend_Controller_Request_Abstract $request)
    {
        $dispatcher = Zend_Controller_Front::getInstance()->getDispatcher();
        if (!$dispatcher->isDispatchable($request)) {
             // Controller exists

             // Exit ();
             $router = Zend_Controller_Front::getInstance()->getRouter();
             $router->addRoute('/:catid', new Zend_Controller_Router_Route('/:catid', array(
                 'module' => 'default' ,
                 'controller' => 'profile' ,
                 'action' => '' // Check your action and controller
             )));
         }
    }
}

And it does not work there is another solution ?

  • 写回答

3条回答 默认 最新

  • doukao8851 2014-04-26 23:37
    关注

    It isn't very clear what this plugin is supposed to do. You've put your logic within routeStartup() which happens before routing takes place. isDispatchable() is always going to return false there, since the module/controller/action to dispatch hasn't yet been determined.

    I would say move the logic to routeShutdown() (which runs after routing), but the purpose of your code seems to be to add a new route if routing fails, which wouldn't achieve anything. You might need to rethink your approach.

    You can change parameters in the request object before the dispatch occurs, which is probably what you want to do.

    评论

报告相同问题?

悬赏问题

  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算