You can assign different layouts to different users using following filter class
1. Add LayoutFilter.php to your protected/components/ folder
class LayoutFilter extends CFilter { protected function preFilter($filterChain) { // logic being applied before the action is executed $roles = Yii::app()->user->getState('roles'); if (!is_array($roles)) $roles = array(); if (in_array(User::ROLE_ADMIN, $roles)) { $filterChain->controller->layout = 'admin/column2'; } else { $filterChain->controller->layout = '//layouts/column2'; } return parent::preFilter($filterChain); } protected function postFilter($filterChain) { // logic being applied after the action is executed return parent::postFilter($filterChain); } }
2. Update protected/components/Controller.php and add following filters
public function filters() { return array( 'rights', array('application.components.LayoutFilter'), ); }
3. Update all controllers and add following filters
public function filters() { return parent::filters() + array( 'postOnly + delete', // we only allow deletion via POST request ); }
cannot work for me .. i m using the yii rights and yii user ..pls help me sir,
This is my mail id balag2012mail@gmail.com
Pls mail me solution..
Pls reply me sir
@balaji If you share your code I can better help you.
Pls give me your mail id i will send the file..
pls send me your mail id sir,
I m using yii rights with yii user extensions
http://www.yiiframework.com/extension/rights/
http://www.yiiframework.com/extension/yii-user
the following extension are using my app
In on login file, how to assign role based change layouts and default url controller
for example, i want admin role to assign the admin_layout.
and i want user role to assign to user_layout
Pls help me sir,
Advance tanks .
You can share your code over here.
You may use http://snipt.org/ or http://codepad.org/
Checkout this post http://tahiryasin.wordpress.com/2013/02/12/how-to-separate-front-and-admin-panel-in-yii-framework/
i m using only one login page, i want to login user and admin. when user login change userlayout and when admin login change adminlayout. otherwise i dont no need front and back panels.
Pls help me.
You can have a role column in your users table, and set that role to the user at login time in UserIdentity.php like
Yii::app()->user->setState(‘role’, $user->role);
And you can check that role at any time anywhere in the application, on the basis of user role you can easily switch layout in any action of any controller by
if(Yii::app()->user->getState(‘role’) == ‘admin’)
{
$this->layout = ‘//layouts/column2’;
}
This line of coding not working for me sir. im using yii rights and yii user extensions..so cannot work.
shall i send my project..pls help me,
Thanxs for your valuable time for me sir,
I got the solution..I m very very Happy sir..
————————————————————————————
//Login Controller
————————————————————————————
if (Yii::app()->user->isSuperuser)
//some actions here ..
$this->redirect(array(‘/mailbox’));
else
$this->redirect(Yii::app()->user->returnUrl);
————————————————————————————
//particular module view control..i.e., mailbox controller
if (Yii::app()->user->isSuperuser)
{
$this->layout=’//layouts/colomn1′;
}
else
{
$this->layout=’//layouts/colomn2′;
}
————————————————————————————–
Happy to hear that!
Ok, share your userIdentity code where you create session and the code where you are trying switch layout.
Can anyone teach me how to write a HTML layout (Howrse.com compatible) or redirect me to a website that has super basic instructions?
Note: any HTML layout format type will work, but to see what I’m lookiing for, go to a Howrse player’s page to see a layout.
Thanks all.
Creating layouts for Howrse.com can take some time to learn and I can’t explain you all the way here in comments.
You may checkout this site http://howrseinfo.com/layout-help-intro
Look #1
Thanks, formatting corrected.