do not have a method or closure named "save"
hello,
i m creating simple registration form in yii but its not work.
when i m using save() method for inserting data into database then its giving me an error.
have anybody any idea about this bug.
please suggest me.
here i m giving all coding and also whole zip file attach with my problem.
SiteConttroller.php
public function actionRegister()
{
$model=new RegisterForm;
// if it is ajax validation request
/*if(isset($_POST['ajax']) && $_POST['ajax']==='login-form')
{
echo CActiveForm::validate($model);
Yii::app()->end();
}*/
// collect user input data
if(isset($_POST['RegisterForm']))
{
$model->attributes=$_POST['RegisterForm'];
$model->save();
// validate user input and redirect to the previous page if valid
}
// display the register form
$this->render('register',array('model'=>$model));
}
register.php
<?php
$this->pageTitle=Yii::app()->name . ’ - Register’;
$this->breadcrumbs=array(
'Login',
);
?>
<h1>Register</h1>
<p>Please fill out the following form with your register credentials:</p>
<div class="form">
<?php $form=$this->beginWidget(‘CActiveForm’, array(
'id'=>'login-form',
'enableClientValidation'=>true,
'clientOptions'=>array(
'validateOnSubmit'=>true,
),
)); ?>
<p class="note">Fields with <span class="required">*</span> are required.</p>
<?php echo $form->errorSummary($model); ?>
<div class="row">
<?php echo $form->labelEx($model,'name'); ?>
<?php echo $form->textField($model,'name'); ?>
<?php echo $form->error($model,'name'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'email'); ?>
<?php echo $form->textField($model,'email'); ?>
<?php echo $form->error($model,'email'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'username'); ?>
<?php echo $form->textField($model,'username'); ?>
<?php echo $form->error($model,'username'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'password'); ?>
<?php echo $form->passwordField($model,'password'); ?>
<?php echo $form->error($model,'password'); ?>
</div>
<div class="row buttons">
<?php echo CHtml::submitButton('Create'); ?>
</div>
<?php $this->endWidget(); ?>
</div><!-- form -->
RegisterForm.php
<?php
/**
-
LoginForm class.
-
LoginForm is the data structure for keeping
-
user login form data. It is used by the ‘login’ action of ‘SiteController’.
*/
class RegisterForm extends CFormModel
{
public $name;
public $email;
public $username;
public $password;
//public $rememberMe;
private $_identity;
/**
* Declares the validation rules.
* The rules state that username and password are required,
* and password needs to be authenticated.
*/
/* public function rules()
{
return array(
// username and password are required
array('name , email, username, password', 'required'),
// rememberMe needs to be a boolean
//array('rememberMe', 'boolean'),
// password needs to be authenticated
//array('password', 'authenticate', 'skipOnError'=>true),
);
}*/
public function rules()
{
return array(
// name, email, subject and body are required
array('name, email, username, password', 'required'),
// email has to be a valid email address
array('email', 'email'),
// verifyCode needs to be entered correctly
array('verifyCode', 'captcha', 'allowEmpty'=>!CCaptcha::checkRequirements()),
);
}
/**
* Declares attribute labels.
*/
/* public function attributeLabels()
{
return array(
'rememberMe'=>'Remember me next time',
);
}*/
/**
* Authenticates the password.
* This is the 'authenticate' validator as declared in rules().
*/
/*public function authenticate($attribute,$params)
{
$this->_identity=new UserIdentity($this->username,$this->password);
if(!$this->_identity->authenticate())
$this->addError('password','Incorrect username or password.');
}*/
/**
* Logs in the user using the given username and password in the model.
* @return boolean whether login is successful
*/
public function register()
{
/*if($this->_identity===null)
{
$this->_identity=new UserIdentity($this->username,$this->password);
$this->_identity->authenticate();
}
if($this->_identity->errorCode===UserIdentity::ERROR_NONE)
{
$duration=$this->rememberMe ? 3600*24*30 : 0; // 30 days
Yii::app()->user->login($this->_identity,$duration);
return true;
}
else
return false;*/
}
public function attributeLabels()
{
return array(
'verifyCode'=>'Verification Code',
);
}
}