Contact Form

After i submitting the contact form it is not saving to database. It showing error like below

Unknown Method – yii\base\UnknownMethodException

Calling unknown method: app\models\ContactForm::save()

Controller-

public function actionContact()

{


    $model = new ContactForm();


    if ($model->load(Yii::$app->request->post()) && $model->contact(Yii::$app->params['adminEmail'])) {


        Yii::$app->session->setFlash('contactFormSubmitted');





        return $this->refresh();


    }


    return $this->render('contact', [


        'model' => $model,


    ]);


}

Model-

<?php

namespace app\models;

use Yii;

use yii\base\Model;

/**

  • ContactForm is the model behind the contact form.

*/

class ContactForm extends Model

{

public &#036;name;


public &#036;email;


public &#036;subject;


public &#036;body;


public &#036;verifyCode;








public static function tablename()


{


	return 'contactform';


}


/**


 * @return array the validation rules.


 */


public function rules()


{


    return [


        // name, email, subject and body are required


        [['name', 'email', 'subject', 'body'], 'required'],


        // email has to be a valid email address


        ['email', 'email'],


        // verifyCode needs to be entered correctly


        ['verifyCode', 'captcha'],


    ];


}





/**


 * @return array customized attribute labels


 */


public function attributeLabels()


{


    return [


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


    ];


}





/**


 * Sends an email to the specified email address using the information collected by this model.


 * @param  string  &#036;email the target email address


 * @return boolean whether the model passes validation


 */


public function contact(&#036;email)


{


    if (&#036;this-&gt;validate()) {


		&#036;form = new contactForm();


		&#036;form-&gt;name = &#036;this-&gt;name;


		&#036;form-&gt;email = &#036;this-&gt;email;


		&#036;form-&gt;subject = &#036;this-&gt;subject;


		&#036;form-&gt;body = &#036;this-&gt;body;


		&#036;form-&gt;save();


	


        /*Yii::&#036;app-&gt;mailer-&gt;compose()


            -&gt;setTo(&#036;email)


            -&gt;setFrom([&#036;this-&gt;email =&gt; &#036;this-&gt;name])


            -&gt;setSubject(&#036;this-&gt;subject)


            -&gt;setTextBody(&#036;this-&gt;body)


            -&gt;send();*/





        return true;


    }


	else{


    return false;


	}


}

}

And the table name is contactform.

You should generate AR model for it. Currently you’re using form model which isn’t about database at all.