For example in my database I have a field called "assigned_to", this contains the integer value of the user ID that the record is assigned to.
I want to configure accessRules() so that the users can only access their own records (when they are logged in) and not anybody elses.
Page 1 of 1
How to ensure users can only access their own records?
#2
Posted 11 February 2010 - 03:35 PM
Not sure if this is the best way to tackle the problem, but I would do something similar to the following in your view controller
public function accessRules()
{
return array(
array('allow',
'actions'=>array('show'),
'expression'=>$databaseModel->assigned_to==Yii::app()->user->id ? true : false,
),
array('deny', // deny all users
'users'=>array('*'),
),
);
}
#3
Posted 12 February 2010 - 05:25 AM
OK I did that but it breaks the 'authenticated' users functionality. Here is my code:
Where I try to access index.php?r=admin, the error message I get says: The requested page does not exist.
public function accessRules()
{
$model=Application::model()->findByPk($id);
return array(
array('allow',
'actions'=>array('list', 'view'),
'expression'=>$model->assigned_to==Yii::app()->user->id ? true : false,
),
array('allow',
'actions'=>array('admin'),
'users'=>array('@'),
),
array('deny',
'users'=>array('*'),
),
);
}Where I try to access index.php?r=admin, the error message I get says: The requested page does not exist.
#4
Posted 12 February 2010 - 06:45 AM
Anyone able to advise?
I think what's happening is that $model is null on the 'admin' view. But it should ignore that really.
I think what's happening is that $model is null on the 'admin' view. But it should ignore that really.
#5
Posted 12 February 2010 - 11:03 AM
GSTAR, on 12 February 2010 - 06:45 AM, said:
Anyone able to advise?
I think what's happening is that $model is null on the 'admin' view. But it should ignore that really.
I think what's happening is that $model is null on the 'admin' view. But it should ignore that really.
Reorder your access rules and put the one you want to give priority to at the top
php:
foreach(array('cat', 'dog', 'cow') as $animal) echo $animal."\n";
python:
[(animal, print(animal)) for animal in ['cat', 'dog', 'cow']]
ruby:
['cat', 'dog', 'cow'].each {|animal| puts animal}
You say Tomato, I say Tomato.
Share this topic:
Page 1 of 1

Help













