rickgrana
(Ricardo Grana)
1
I want to set a rule like: if a Post is closed, just the admin can alter it.
I intend to do it by an expression on accessRules, so i did it as below:
Then, i give an error message: can not find model Post! But the Post::ROLE_ADMIN reference works!
Any idea how to do that?
Eliovir
(Eliovir)
2
I'm not an expert, but this line
is strange.
Armando
(Armandoricky)
3
Do you can show, what return in $post = $this->loadPost() ; 
rickgrana
(Ricardo Grana)
4
[/quote]
Quote
I'm not an expert, but this line
'expression' => "!$post->isClosed()",
is strange.
It is just an idea. Expression evaluates the expression to validate the rule, doesn't it?
Quote
Do you can show, what return in $post = $this->loadPost() ;
It's the normal load method that each Controller creates. In this case:
public function loadPost($id=null)
{
if($this->_post===null)
{
if($id!==null || isset($_GET['id']))
$this->_post=Post::model()->findbyPk($id!==null ? $id : $_GET['id']);
if($this->_post===null)
throw new CHttpException(500,'O modelo Post não existe.');
}
return $this->_post;
}
Thx
rickgrana
(Ricardo Grana)
5
Sorry for double post, but I still needs a help on this issue.
qiang
(Qiang Xue)
6
Your expression cannot reference variable $post since it is not defined.
You should use
Yii::app()->controller->loadPost() && !Yii::app()->controller->loadPost()->isClosed()
rickgrana
(Ricardo Grana)
7
Thanks Qiang! Now it'´s working!
This observation should be added to the guide ^^