Class 'app\controllers\app\models\Register' not found

Hi, why I am having this fatal error


Class 'app\controllers\app\models\Register' not found

but I already generated a form via Gii Tool

This is what the code generated by Gii Tool and I put it in sitecontroller

in my conntroller




 public function actionRegister()

    {

        $model = new app\models\Register();


        if ($model->load(Yii::$app->request->post())) {

            if ($model->validate()) {

                // form inputs are valid, do something here

                return;

            }

        }


        return $this->render('site/register', [

            'model' => $model,

        ]);

    }







views/register.php




<?php


use yii\helpers\Html;

use yii\widgets\ActiveForm;


/* @var $this yii\web\View */

/* @var $model app\models\Register */

/* @var $form ActiveForm */

?>

<div class="site-register">


    <?php $form = ActiveForm::begin(); ?>


        <?= $form->field($model, 'username') ?>

        <?= $form->field($model, 'password') ?>

    

        <div class="form-group">

            <?= Html::submitButton('Submit', ['class' => 'btn btn-primary']) ?>

        </div>

    <?php ActiveForm::end(); ?>


</div><!-- site-register -->






models/register.php




<?php


namespace app\models;


use Yii;


/**

 * This is the model class for table "user".

 *

 * @property integer $id

 * @property string $username

 * @property string $password

 */

class Register extends \yii\db\ActiveRecord

{

    /**

     * @inheritdoc

     */

    public static function tableName()

    {

        return 'user';

    }


    /**

     * @inheritdoc

     */

    public function rules()

    {

        return [

            [['username', 'password'], 'required'],

            [['username', 'password'], 'string', 'max' => 50]

        ];

    }


    /**

     * @inheritdoc

     */

    public function attributeLabels()

    {

        return [

            'id' => 'ID',

            'username' => 'Username',

            'password' => 'Password',

        ];

    }

}







I believe the problem is the way you are calling the class in the controller, you are not using the correct namespace:

[color="#000000"] $model [/color][color="#666600"]=[/color] [color="#000088"]new[/color][color="#000000"] app[/color][color="#666600"]\[/color][color="#000000"]models[/color][color="#666600"]\[/color][color="#660066"]Register[/color]color="#666600";[/color]

Try:





$model = new Register();



Thank you…:)

You should put


 use app\models\register