do not have a method or closure named "save"

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'=&gt;'login-form',


'enableClientValidation'=&gt;true,


'clientOptions'=&gt;array(


	'validateOnSubmit'=&gt;true,


),

)); ?>

    &lt;p class=&quot;note&quot;&gt;Fields with &lt;span class=&quot;required&quot;&gt;*&lt;/span&gt; are required.&lt;/p&gt;


	&lt;?php echo &#036;form-&gt;errorSummary(&#036;model); ?&gt;


    &lt;div class=&quot;row&quot;&gt;


            &lt;?php echo &#036;form-&gt;labelEx(&#036;model,'name'); ?&gt;


            &lt;?php echo &#036;form-&gt;textField(&#036;model,'name'); ?&gt;


            &lt;?php echo &#036;form-&gt;error(&#036;model,'name'); ?&gt;


    &lt;/div&gt;


    &lt;div class=&quot;row&quot;&gt;


            &lt;?php echo &#036;form-&gt;labelEx(&#036;model,'email'); ?&gt;


            &lt;?php echo &#036;form-&gt;textField(&#036;model,'email'); ?&gt;


            &lt;?php echo &#036;form-&gt;error(&#036;model,'email'); ?&gt;


    &lt;/div&gt;





    &lt;div class=&quot;row&quot;&gt;


            &lt;?php echo &#036;form-&gt;labelEx(&#036;model,'username'); ?&gt;


            &lt;?php echo &#036;form-&gt;textField(&#036;model,'username'); ?&gt;


            &lt;?php echo &#036;form-&gt;error(&#036;model,'username'); ?&gt;


    &lt;/div&gt;





    &lt;div class=&quot;row&quot;&gt;


            &lt;?php echo &#036;form-&gt;labelEx(&#036;model,'password'); ?&gt;


            &lt;?php echo &#036;form-&gt;passwordField(&#036;model,'password'); ?&gt;


            &lt;?php echo &#036;form-&gt;error(&#036;model,'password'); ?&gt;


    &lt;/div&gt;


	








    &lt;div class=&quot;row buttons&quot;&gt;


           &lt;?php echo CHtml::submitButton('Create'); ?&gt;


    &lt;/div&gt;

<?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 &#036;name;


    public &#036;email;


    public &#036;username;


    public &#036;password;


    //public &#036;rememberMe;





    private &#036;_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'=&gt;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'=&gt;&#33;CCaptcha::checkRequirements()),


		);


	}





    /**


     * Declares attribute labels.


     */

/* public function attributeLabels()

    {


            return array(


                    'rememberMe'=&gt;'Remember me next time',


            );


    }*/





    /**


     * Authenticates the password.


     * This is the 'authenticate' validator as declared in rules().


     */


    /*public function authenticate(&#036;attribute,&#036;params)


    {


            &#036;this-&gt;_identity=new UserIdentity(&#036;this-&gt;username,&#036;this-&gt;password);


            if(&#33;&#036;this-&gt;_identity-&gt;authenticate())


                    &#036;this-&gt;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(&#036;this-&gt;_identity===null)


            {


                    &#036;this-&gt;_identity=new UserIdentity(&#036;this-&gt;username,&#036;this-&gt;password);


                    &#036;this-&gt;_identity-&gt;authenticate();


            }


            if(&#036;this-&gt;_identity-&gt;errorCode===UserIdentity::ERROR_NONE)


            {


                    &#036;duration=&#036;this-&gt;rememberMe ? 3600*24*30 : 0; // 30 days


                    Yii::app()-&gt;user-&gt;login(&#036;this-&gt;_identity,&#036;duration);


                    return true;


            }


            else


                    return false;*/


    }


	public function attributeLabels()


{


	return array(


		'verifyCode'=&gt;'Verification Code',


	);


}

}

use code tags for your fragments

try using




if ($model->save())

  $this->redirect(array('index'));



As far as I know, you need to extend CActiveRecord, not CFormModel. CFormModel isn’t used to persist data directly and doesn’t define the save() method.