doujiao4705 2013-05-11 12:05
浏览 12
已采纳

@如何在YII中的accessRules中运行

I am developing a demo project using YII to learn it.

My doubt is on accessRules() function.

In my project to check the user access(For registered users), I am keeping a value in a session on user login and i'm checking the user access using 'expression' context parameter in accessRules.

Something like:

    array('allow', 
        'actions'=>array('create','edit','delete'),
        'expression' => '$this->isUser()' //isUser() returns bool value by checking session.
    ),

For this same functionality i like to use 'users' context parameter. But i am unable to understand how '@' is referring Authenticated Users.

Please let me know

  1. How '@' is functioning in accessRules?.
  2. Can we change '@' to other Special characters or to unique string?.
  • 写回答

1条回答 默认 最新

  • duanmei1536 2013-05-11 12:39
    关注

    What are you using to detect that the user is logged in? A simple session variable set manually by yourself?

    I suggest you take a look here to read about login for Yii:
    http://www.yiiframework.com/doc/guide/1.1/en/topics.auth

    And for a example that already has login system implemented you could take a look at the blog demo that comes with the download of the framework in the demos folder. If you check one by one the files that are being used in the login process you could easily copy them and integrate them into your project. (like; sitecontroller/login action, loginform, useridentity component, and so on).

    The '@' symbol is representing a logged in user and '*' means all users.

    So I know that in the 'users' key of the array I can put one of this values:

    • '@' all logged in users
    • '*' all users
    • 'array('username1','username2','username3')' - only specific users

    Other resource that might be useful:
    http://www.larryullman.com/2010/01/04/simple-authentication-with-the-yii-framework/

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

报告相同问题?

悬赏问题

  • ¥15 stata webuse报错
  • ¥15 TypeError: Cannot read properties of undefined (reading 'status')
  • ¥15 如何利用AI去除图片中的竹架子
  • ¥15 python 写个基金爬取的代码,自动卖出功能
  • ¥15 Linux系统启动不起来
  • ¥15 为什么运行仿真数码管不亮(语言-c语言)
  • ¥15 陈仁良《直升机飞行动力学》小扰动线化方程如何推导
  • ¥30 如何解决'Failed to format this callback filepath: "{val_acc:.2f}.hdf5". Reason: \'val_accuracy\''
  • ¥15 OpenGL渲染效率
  • ¥60 关于网络前后端:丢包攻击、漏洞后门、渗透这些