donglang7236 2014-09-23 08:29
浏览 20
已采纳

ZF2 REST API + ACL不会在predispatch中返回操作名称

Ok, i have a problem, but i think it is not so complicated, so it would be great if someone helped me. 1) I have UserController that extends AbstractRestfulController and it works fine. 2) Then i needed to check the permission to access actions of this controller. If I use "checkPermission" method in every controller it works pretty good, but I want to make this method done in a preDispatch event. And here are some problems: I do like this: Module.php

public function onBootstrap(MvcEvent $e)
{
    $em = $e->getApplication()->getEventManager();
    $em->attach('dispatch', array($this, 'preDispatch'), +100);
}

My method "checkPermission" checks like this (nothing special I think):

if (!$this->isAllowed($role, $this->routeMatch->getParam('controller'), $this->routeMatch->getParam('action'))) {

So the problem: getParam('action') returns null (It means, that in a preDispatch event application doesn't know what action it needs to execute). How can I make it work like I want? Or here is the main question: When does getParam('action') can return value? Only in onDispatch event?

  • 写回答

1条回答 默认 最新

  • doutuoji8418 2014-09-24 05:13
    关注

    since its a restful api, it will never return action name. in added with applying ACL to the Rest API is not a good practice. Use Rest API Authentication HEADERS instead of ACL.
    refer this link
    --SJ

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

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