Models in accessRules expression

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 exp​ression 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?

I'm not an expert, but this line

is strange.

Do you can show, what return in $post = $this->loadPost() ;  ???

[/quote]

Quote

I'm not an expert, but this line
'exp​ression' => "!$post->isClosed()",

is strange.

It is just an idea. Exp​ression evaluates the exp​ression 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

Sorry for double post, but I still needs a help on this issue.

Your exp​ression cannot reference variable $post since it is not defined.

You should use



Yii::app()->controller->loadPost() && !Yii::app()->controller->loadPost()->isClosed()


Thanks Qiang! Now it'´s working!

This observation should be added to the guide ^^