Hi I finished my first Yii powered site and I can tell you I love Yii!
But I am stuck on something that is probably simple but I just dont get it:(
I dont know how to dynamicly fill access rules list so only user who made post can edit it besides admins. I am using user module so people can register to add posts.
In my controler I have:
public function accessRules()
{
// so only owner of the post can edit
//if(isset($_GET['id']))
if($_GET["id"]){
if(Yii::app()->user->getId() === $_GET["id"])
$user_updater = Yii::app()->user->username;
}
return array(
array('allow', // allow all users to perform 'index' and 'view' actions
'actions'=>array('index','view'),
'users'=>array('*'),
),
array('allow', // allow authenticated user to perform 'create' and 'update' actions
'actions'=>array('create'),
'users'=>array('@'),
),
array('allow', // allow authenticated user to perform 'create' and 'update' actions
'actions'=>array('update'),
'users'=>array($user_updater,'kuzmanovicb'),
),
array('allow', // allow admin user to perform 'admin' and 'delete' actions
'actions'=>array('admin','delete'),
'users'=>array('kuzmanovicb'),
),
array('deny', // deny all users
'users'=>array('*'),
),
);
}
But on localhost/yiitest/oglasi/1 I get error: Property "CWebUser.username" not defined.
I was trying to make admins generated dynamicly with something like
public function getusers(){
$usersFromDB= Account::model()->findAll();
foreach ($usersFromDB as $val)
{
$users[]=$val->name;
}
retutn $users;
}
but dont know how to set this up for my example
In my model I have
public function relations()
{
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
Yii::import('application.modules.user.models.*');
return array(
'kategorija' => array(self::BELONGS_TO, 'Kategorija', 'kategorija_id'),
'user' => array(self::BELONGS_TO, 'User', 'user_id'),
);
}
and this works.
I want to thank You all who can help me.
Best Regards