Yii Blog Demo: How to restrict comment creation?

Hello out there.

I am still quite new to yii and use the Blog-demo to learn it.

This works quite well, so thanks for putting all of this up.

One question arose:

On the page about comment-creation


It allows basically everybody to create a comment, mostly (I guess) as it is called via the actionView of the Post-Controller, which is open for every body.

But how do I do this if I want that everybody views the Posts, but only registered users can create a new comment?

In the comment-controller I can not set this up, as it is not called from the Post-Controller, right?

If I understand it correctly, the post-controller gets its own model of the comment to save it, without the comment-controller.

Any ideas that point me to the right direction highly welcome…


Hi gb5256,

I’d suggested to use Yii::app()->user->isGuest in your case. You may add this check in your view files and before making comment addition in the controller.

You may try to start to play with RBAC also, but I’d leave it for the next steps of your yii-studies.

In your thoughts you’re quite right, even though some of them sound a bit unusual to me :)

[color="#008000"]NOTE: moved to proper section (General Discussion for Yii 1.1.x instead of Tips, Snippets and Tutorials)[/color]