I really tried hard to follow the tutorial in the definitive guide to Yii and it is not really clear to me exactly how to implement this tool.
Step 1 is straightforward. It shows a controller script as follows:
public function actionLogin()
{
$model = new LoginForm;
$form = new CForm('application.views.site.loginForm', $model);
if($form->submitted('login') && $form->validate())
$this->redirect(array('site/index'));
else
$this->render('login', array('form'=>$form));
}
Step 2 describes a configuration array of elements to be returned back to the controller:
return array(
'title'=>'Please provide your login credential',
'elements'=>array(
'username'=>array(
'type'=>'text',
'maxlength'=>32,
),
'password'=>array(
'type'=>'password',
'maxlength'=>32,
),
'rememberMe'=>array(
'type'=>'checkbox',
)
),
'buttons'=>array(
'login'=>array(
'type'=>'submit',
'label'=>'Login',
),
),
);
Then in step 3 there is a sample code for the view file which does not include any code other than the following:
<h1>Login</h1>
<div class="form">
<?php echo $form; ?>
</div>
There are a few things that aren’t making sense here. First of all, when I tried to run this script as is, I got an error “$form variable undefined” referencing the view file. The other issue is what happened to the element array? Where is that supposed to be? It is completely missing from the picture in the actual implementation. Is that defined in the loginForm model or in some function in the controller? This may seem obvious to some of you but I am just starting out here so any help would be appreciated.