Login form in index page

How can i put in the index page the login form????

First you will need to modify your index action and pass in a LoginForm.




  public function actionIndex()

  {

    $loginForm = new LoginForm();

    $this->render('index', array('loginForm'=>$loginForm));

  }



Then you will need to add your form to the index view.




<div class="form">

<?php $form=$this->beginWidget('CActiveForm', array(

        'action'=>array('site/login'),

	'id'=>'login-form',

)); ?>


	<p class="note">Fields with <span class="required">*</span> are required.</p>


	<div class="row">

		<?php echo $form->labelEx($loginForm,'username'); ?>

		<?php echo $form->textField($loginForm,'username'); ?>

		<?php echo $form->error($loginForm,'username'); ?>

	</div>


	<div class="row">

		<?php echo $form->labelEx($loginForm,'password'); ?>

		<?php echo $form->passwordField($loginForm,'password'); ?>

		<?php echo $form->error($loginForm,'password'); ?>

		<p class="hint">

			Hint: You may login with <tt>demo/demo</tt> or <tt>admin/admin</tt>.

		</p>

	</div>


	<div class="row rememberMe">

		<?php echo $form->checkBox($loginForm,'rememberMe'); ?>

		<?php echo $form->label($loginForm,'rememberMe'); ?>

		<?php echo $form->error($loginForm,'rememberMe'); ?>

	</div>


	<div class="row buttons">

		<?php echo CHtml::submitButton('Login'); ?>

	</div>


<?php $this->endWidget(); ?>

</div><!-- form -->



Dont’t work…

can you help me????

what is the error you are getting?

I don’t have an error but don’t display the login form in the index page…

I have 2 themes one when the user is authenticated and one when user is guest…

i have a problem that when i login redirect another time in the login form with another theme…

i’d like to suggest that you create a portlet and render it inside your index view, by using this approach:




$this->widget('myLoginPortlet',array('title'=>'Login'));



the major advantage in doing this way is that you’ll be able to reuse the portlet in every page you want

there is a XLoginPortlet in the extensions page, made by Qiang

http://www.yiiframework.com/extension/login/

hope it helps!!

:)

regards!!

Nice. It works for me. and i done some small change to look it better.

Here it is:

public function actionIndex()

{


            if(Yii::app()-&gt;user-&gt;isGuest){


                &#036;loginForm = new LoginForm();


                &#036;this-&gt;render('index', array('loginForm'=&gt;&#036;loginForm));


            }


            else


                &#036;this-&gt;render('index1');


}

when user are login then they can see a new home page instead of login page.