0

I'm beginner to learn yii2.

I am getting this error:

syntax error, unexpected '$model' (T_VARIABLE) form yii2

Here is my code:

public function actionForms(){
    $model = new form11();  // <<error on this line
    if ($model->load(Yii::$app->request->post()) && $model->save()) {
        Yii::$app->session->setFlash('contactFormSubmitted');
halfer
  • 19,824
  • 17
  • 99
  • 186
  • The code you've posted looks fine, so the issue may be before that code. Are you using an IDE, such as Netbeans or PhpStorm? If not, get one installed and paste your code in - it will help you find your error. – halfer Apr 07 '17 at 16:03
  • it's a syntax error, but the declaration is ok at this point. See if any of these cases are happenning: http://stackoverflow.com/questions/18050071/php-parse-syntax-errors-and-how-to-solve-them/18092267#18092267 – F.Igor Apr 07 '17 at 16:04
  • i copy example form (https://www.cloudways.com/blog/creating-contact-form-in-yii2/ ) – Bez Sattaya Apr 07 '17 at 16:07
  • You have some missed closing / open { } ...eg : you must check for right opne closing bracked in your functions declaration .. – ScaisEdge Apr 07 '17 at 16:38

1 Answers1

0

Check two things ...

  1. You have created model named form11 in /models directory. (With name space)
  2. Include that model in this controller file.
Hmmm
  • 562
  • 3
  • 11