[font="Arial,"][size="4"]I keep on reading this tutorial of Yii framework over and over again Yii Framework Form Tutorial[/size][/font]
[font="Arial,"][size="4"]I already created my Model with this following codes[/size][/font]
[font="Arial,"][size="4"]
class LoginForm extends CFormModel{
public $username;
public $password;
public $rememberMe = false;
private $_identity;
public function rules(){
return array(
/* array(,,)
* functions required and boolean are built-in validators of the yii framework.
* you can invoke your own function by defining your own function
*/
array('username','password','required'),
array('rememberMe','boolean'),
array('password','authenticate'),
);
}
public function authenticate(){
$this->_identity = new UserIdentity($this->username,$this->password);
if(!$this->_identity->authenticate()){
$this->addError("password","Incorrect Username or Password");
}
}
public function attributeLabels(){
return array(
'username'=>"Username",
'password'=>"Password",
'rememberMe'=>"Remember Me",
);
}
}
[/size][/font]
[font="Arial,"][size="4"]and my Action function with this codes in my controller[/size][/font]
[font="Arial,"][size="4"]
public function actionLogin(){
//calls the Login Model that will be used in this action
$model = new LoginForm;
if(isset($_POST["LoginForm"])){
//collects user input
$model->attributes = $_POST["LoginForm"];
//validates user input using the model rules and redirects back to
//previous page when user input is invalid
if($model->validate()){
$this->redirect(Yii::app()->user->returnUrl);
}
//redisplay the login form
$this->render('login',array('loginModel'=>$model));
}
}
[/size][/font]
[font="Arial,"][size="4"]and lastly my view[/size][/font]
[font="Arial,"][size="4"]
<div class="form">
<?php
$formlogin = $this->beginWidget('CActiveForm');
echo $formlogin->errorSummary($model);
?> $formlogin = $this->beginWidget('CActiveForm');
echo $formlogin->errorSummary($model);
?>
$formlogin->label($model,'username');
$formlogin->textField($model,'username');
?>
$formlogin->label($model,'password');
$formlogin->passwordField($model,'password');
?>
$formlogin->checkBox($model,'rememberMe');
$formlogin->label($model,'rememberMe');
?>
echo CHtml::submitButton('Login');
?>
$this->endWidget();
?>
</div>
[/size]
[/font]
[font="Arial,"][size="4"]and i always came out with this error[/size][/font]
[font="Arial,"][size="4"]
Undefined variable: model
[/size][/font]
[font="Arial,"][size="4"]do i miss something? please let me know… I know this is kinda simple but I am a first-timer in using such component-based MVC frameworks… Thanks[/size][/font]