Reputation: 1671
How can I create a single static page in Yii that only logged in users can view?
Upvotes: 2
Views: 775
Reputation: 31
You must create an action inside your controller, say public function actionStaticpage()
, and:
This action will handle the view rendering of the static contents you may want to show, i.e. some instructions/faq for logged users, a tutorial, etc. For instance:
public function actionStaticpage() {
$this->render('faq');
}
You'll now have to specify that this action is intended to be viewable only for logged users. You may accomplish this by using your Controller's function accessRules()
. It would be something like this:
public function accessRules()
{
return array(
array('allow', // allow authenticated user to perform these actions
'actions'=>array('staticpage'),
'users'=>array('@'),
),
);
}
And that's it. You can also make your Staticpage a little more dynamic, for example by having a parameter inside it, specifying which static content you want to display public function actionStaticpage($page)
and then using switch
or if
statements to correctly display contents.
Upvotes: 3
Reputation: 437584
There is good documentation on how to enable Yii's access control filter for a controller action on the guide. You will have to make a controller action that displays a static view, and limit access to that action based on the tutorial.
Upvotes: 3