ronallensmith 3 Posted October 6, 2013 Author Report Share Posted October 6, 2013 I played around with this for some time and couldn't get it to work properly. It removes "Delete" button for both authenticated users: array( 'class'=>'CButtonColumn', 'buttons'=>array ( 'delete'=>array ( 'visible'=>"(Yii::app()->user->checkAccess('demo')) ? true : false;", ) ) ), My access rules are: public function accessRules() { return array( array('allow', // allow all users to perform 'index' and 'view' actions 'actions'=>array('index','view'), 'users'=>array('*'), ), array('deny', // can't create, update, delete 'actions'=>array('create','update','delete'), 'users'=>array('demo'), ), array('allow', // can create, update, delete 'actions'=>array('create','update','delete'), 'users'=>array('admin'), ), array('allow', // can access CGridView 'actions'=>array('admin'), 'users'=>array('admin','demo'), ), array('deny', // deny all users 'users'=>array('*'), ), ); } So, the CGridView shows for both users, which is what I want, but the "Delete" button doesn't appear for both users which is what I don't want. The good thing though is that I'm not getting errors with this code. I'll keep working with what you gave me though. Quote Link to post Share on other sites
Edward 108 Posted October 7, 2013 Report Share Posted October 7, 2013 The checkAccess() method performs an access check for the user we both should be using either Yii::app()->user->Name or Yii::app()->user->Id to find the actual username of the logged in user for static authentication values which you have. I hope for both of our sakes we have the correct answer this time. 'visible'=>"(Yii::app()->user->Name==='admin') ? true : false;", This was actually the first time i had to go into investigate CWebUser a little more, i didn't understand my self why static actually work but now i do. I am using database authentication with my website but i truly understand why you are using static values, if i were in your situation i would do the same. Quote Link to post Share on other sites
ronallensmith 3 Posted October 7, 2013 Author Report Share Posted October 7, 2013 Looks like that's the one!! Yea!! I was actually using Yii::app()->user->name == 'admin' about a week ago, but it didn't work because I didn't kow the correct syntax, and it was erroring out so I abandoned it. The key was the "", the === and the ternary. I can't find this anywhere I was looking. Thanks Edward. Here's the whole thing as intended: array( 'class'=>'CButtonColumn', 'buttons'=>array ( 'delete'=>array ( 'visible'=>"(Yii::app()->user->name==='admin') ? true : false;", ), 'update'=>array ( 'visible'=>"(Yii::app()->user->name==='admin') ? true : false;", ) ) ), Now, any authenticated user, other than admin will only see a "View" button--admin sees "View", "Update" and "Delete". I can retire this project now. Thanks again. Quote Link to post Share on other sites
Edward 108 Posted October 7, 2013 Report Share Posted October 7, 2013 Its good we finally managed to work it out together with this code i knew it was nothing that we couldn't handle. If you have any other issues in the future i would be happy to help of course them being Yii related questions. Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.