in my app after i login if i click home its showing login page and can login again witout logout…, this should not happen. before i logout if i click to home then it should redirect to other page.

can anybody help me to achieve this??

[size=2]What is your home URL. is this URl needs a authorization to access?[/size]



this is my home url where user can log in.

authentication will happen here and once username and password are valid then it will redirect from user model to crm model

Ok so,if User logged in then you have to change this URL …is it correct ?

obviously, it vl redirect into crm/index after user login. But again if i click home login page will come and can login again b4 logout. But i need like once user login., before logout., if he click home then also it should redirect to crm/index.

If it is then …you can put a condition in your view/layout file to change a URL according to User logged in Condition.

Use  if(Yii::app->user->isGuest) { "show login link";}{ "show another link"}

not working., getting error unexpected T_IF.

my layout/menu code is like

<div id="mainmenu">

	&lt;?php &#036;this-&gt;widget('zii.widgets.CMenu',array(


			array('label'=&gt;'Home', 'url'=&gt;array('/site/index')),

			array('label'=&gt;'Users', 'url'=&gt;array('/user/index'),'visible'=&gt;Yii::app()-&gt;user-&gt;id===&quot;admin&quot;),

			array('label'=&gt;'CRM Data', 'url'=&gt;array('/crmdatadetails/index'), 'visible'=&gt;&#33;Yii::app()-&gt;user-&gt;isGuest),


			array('label'=&gt;'Logout ('.Yii::app()-&gt;user-&gt;name.')', 'url'=&gt;array('/site/logout'), 'visible'=&gt;&#33;Yii::app()-&gt;user-&gt;isGuest)


			{ &#036;this-&gt;redirect(array('/user/index'));}

			{ &#036;this-&gt;redirect(array('crmdatadetails/index'));}




&lt;/div&gt;&#60;&#33;-- mainmenu --&#62;


Have you stored value in session?

no., not used session anywhere…

Ohh man you are doing a wrong code here. Let me give you a correct code here. Just wait a minute.


please see this link and you can store the value in session

Keep this code same it is.

<?php $this->widget('zii.widgets.CMenu',array(


array('label'=>'Home', 'url'=>array('/site/index')),

array('label'=>'Users', 'url'=>array('/user/index'),'visible'=>Yii::app()->user->id==="admin"),

array('label'=>'CRM Data', 'url'=>array('/crmdatadetails/index'), 'visible'=>!Yii::app()->user->isGuest),

array('label'=>'Logout ('.Yii::app()->user->name.')', 'url'=>array('/site/logout'), 'visible'=>!Yii::app()->user->isGuest))



And please tell me where you want to execute this code.


{ $this->redirect(array('/user/index'));}

{ $this->redirect(array('crmdatadetails/index'));}


  1. When user click on Home


  1. After user logged in into the application.

the code should execute after user logged in and click on home.

In your current code you have Home link to array(‘label’=>‘Home’, ‘url’=>array(’/site/index’)),

So, What i am assuming here is you want to change this URL according to the user logged in condition. is it correct ??

Could you please check this code.

<?php $this->widget('zii.widgets.CMenu',array(


array('label'=>'Home', 'url'=>array('/site/index'),'visible'=>Yii::app()->user->isGuest),

array('label'=>'Home', 'url'=>array('crmdatadetails/index'),'visible'=>!Yii::app()->user->isGuest),

array('label'=>'Users', 'url'=>array('/user/index'),'visible'=>Yii::app()->user->id==="admin"),

array('label'=>'CRM Data', 'url'=>array('/crmdatadetails/index'), 'visible'=>!Yii::app()->user->isGuest),

array('label'=>'Logout ('.Yii::app()->user->name.')', 'url'=>array('/site/logout'), 'visible'=>!Yii::app()->user->isGuest)),



Is this what you want?

My above given code will change the home URL according to the User logged in condition. Could you please replace it in your current code and let me know if you need anything else.

no., no., see i have only one menu very first


      k here user can log in and if user is valid then i am going to display menus

Home | User |CRM | Logout(user)and it vl redirect to r=crm/index

before i click logout if i click Home then login page z coming., i want it like if user click Home before logout then it should redirect into r=crm/index only

thanks its working now.

but i have one more small issue that i am redirecting to crm/index at 3 places.

1st : after user login.,

2nd : in menu i have CRM option na., if i click then also it will redirect to same crm/index

3rd : if i click home before logout.

my problem is afteer user loged in, menus mean Home and CRM z getting focused. i dont want menus to focus like that

is there any solution???

Well first of all you have to be clear with your requirements that what you want to show user as a logged in user and what you want to show as a non- logged in user. based in that you can re-arrange menu items.So, its all up to you what you want.

And regarding your another question related to focus. i am assuming that you are talking about Active menu item. is it correct ?

if yes then you can set a active attribute to true/false in your menu item.

ya., focus mean active only., i fixed it.

Thanks alot:)