Where can i set layout for the site if user is logged in?
Is there a place where this can be done?
Ex:a proper layout for admin users
Where can i set layout for the site if user is logged in?
Is there a place where this can be done?
Ex:a proper layout for admin users
Hello!
If you want for all controllers, in your base controller, normally the Controller.php that is in the components directory, you can override the beforeAction() method and check if the user is a guest or not.
E.g.
public function beforeAction($action)
{
if(!Yii::app()->user->isGuest))
{
Yii::app()->layout = 'admin';
}
else
{
Yii::app()->layout = 'guest';
}
return parent::beforeAction($action);
}
If you want just for a specific controller then you just need to declare a public property at the beginning.
E.g.
class SiteController extends Controller
{
public $layout = 'admin';
...
}
Remember that ‘admin’ and ‘guest’ means that you need to have a ‘admin.php’ and ‘guest.php’ inside your layouts directory (e.g. webroot/protected/views/layouts/)
thanks