I would like to know how can use login form and registration form in Yii user module into layouts/main.php like facebook index page.If anyone can please give me the details..
Thanks in advance...
You need to use a widget. Here's a short crash course on making a widget:
Create LoginFormWidget.php
here: /protected/components/LoginFormWidget.php
Create the view folder for your widgets here /protected/components/views/
Create the view file for your LoginFormWidget
, like so: /protected/components/views/loginFormWidget.php
Put the following code in your LoginFormWidget.php
file:
class LoginFormWidget extends CWidget
{
/**
* Is called when $this->beginWidget() is called
*/
public function init()
{
}
/**
* Is called when $this->endWidget() is called
*/
public function run()
{
$model = new LoginForm;
$this->render('loginFormWidget', array('model'=>$model));
}
}
Add teh view file, make sure that you specify which action will be used:
<div class="form">
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'login-form',
'enableAjaxValidation'=>true,
'clientOptions'=>array('validateOnSubmit'=>true),
'htmlOptions'=>array('class'=>'customClass'),
'action' => array('site/login'), // this is is the action that's going to process the data
)); ?>
<?php echo $form->labelEx($model,'email'); ?>
<?php echo $form->textField($model,'email'); ?>
<?php echo $form->error($model,'email'); ?>
<?php echo $form->labelEx($model,'password'); ?>
<?php echo $form->passwordField($model,'password'); ?>
<?php echo $form->error($model,'password'); ?>
<?php echo CHtml::submitButton('Log in!'); ?>
<?php $this->endWidget(); ?>
</div>
Finally, call the widget in your main.php
file, like so:
<?php $this->widget('LoginFormWidget'); ?>
Good luck!