douyu9012 2014-08-23 13:31
浏览 71
已采纳

Yii:restfullyii在restEvents上的扩展accessRules

He there,

I've been using the restfullyii extension for a while now, and everything is working great. (http://www.yiiframework.com/extension/restfullyii/)

I was just wondering if the following is possible:

  • Admin is allowed to do all REST.GET, REST.PUT, REST.POST and REST.DELETE
  • Normal users can only use the own defined ones in restEvents.

accessRules is looking like this:

public function accessRules()
{
    return array(
        array('allow', 
            'actions'=>array('REST.GET.SPECIAL'),
            'users'=>array('@'),
        ),
        array('allow', // allow admin user to perform 'admin' actions
            'actions'=>array('REST.GET', 'REST.PUT', 'REST.POST', 'REST.DELETE'),
            'users'=>Yii::app()->getModule('user')->getAdmins(),
        ),
        array('deny',  // deny all users
            'users'=>array('*'),
        ),
    );
}

restEvents is looking like this:

public function restEvents()
{ 
    $this->onRest('req.get.special.render', function() {
        /// blabla code
    });
}

I can't seem to find it in the documentation.

Thanks a lot!

  • 写回答

1条回答 默认 最新

  • dssk35460 2014-08-27 17:58
    关注

    I figured it out with the following:

     /**
     * req.auth.uri
     *
     * return true to allow access to a given uri / http verb;
     * false to deny access to a given uri / http verb;
     *
     * @return (bool) default is true
     */ 
    $this->onRest(req.auth.uri, function($uri, $verb) {
        return true;
    });
    

    This will allow you to block/allow particular users in the controller. Just put it in the restEvents() method.

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

报告相同问题?

悬赏问题

  • ¥15 python:excel数据写入多个对应word文档
  • ¥60 全一数分解素因子和素数循环节位数
  • ¥15 ffmpeg如何安装到虚拟环境
  • ¥188 寻找能做王者评分提取的
  • ¥15 matlab用simulink求解一个二阶微分方程,要求截图
  • ¥30 乘子法解约束最优化问题的matlab代码文件,最好有matlab代码文件
  • ¥15 写论文,需要数据支撑
  • ¥15 identifier of an instance of 类 was altered from xx to xx错误
  • ¥100 反编译微信小游戏求指导
  • ¥15 docker模式webrtc-streamer 无法播放公网rtsp