Active Record error help

Hello,

I do not understand why this is happening.

I am trying to create a CRUD, I have already a Profile.php model in:

frontend/models/Profile.php

The error I am getting is:

[php]

PHP Fatal Error – yii\base\ErrorException

Class ‘frontend\models\ActiveRecord’ not found

  1. in C:\xampp\htdocs\yii2build\frontend\models\Profile.php at line 81

72737475767778798081828384858687888990 return $this->hasOne(Gender::className(), [‘id’ => ‘gender_id’]);

}





/**     * behaviors to control time stamp, don't forget to use statement for expression * */


public function behaviors() {


    return [


        'timestamp' => [


            'class' => 'yii\behaviors\TimestampBehavior',


            'attributes' => [


                ActiveRecord::EVENT_BEFORE_INSERT => ['created_at', 'updated_at'],


                ActiveRecord::EVENT_BEFORE_UPDATE => ['updated_at'],],


            'value' => new Expression('NOW()'),


        ],


    ];


}





/**     * uses magic getGender on return statement * */


public function getGenderName() {


    return $this->gender->gender_name;
  1. yii\base\ErrorHandler::handleFatalError()

$_GET = [

[\php]

But in my database I have the "created_at" and "updated_at"

Here is my Profile.php file:

[php]

<?php

namespace frontend\models;

use Yii;

use common\models\User;

use yii\helpers\Url;

use yii\helpers\Html;

use yii\helpers\ArrayHelper;

use yii\db\Expression;

/**

  • This is the model class for table "profile".

  • @property string $id

  • @property string $user_id

  • @property string $first_name

  • @property string $last_name

  • @property string $birthdate

  • @property string $gender_id

  • @property string $created_at

  • @property string $updated_at

  • @property Gender $gender

*/

class Profile extends \yii\db\ActiveRecord {

/**


 * @inheritdoc


 */


public static function tableName() {


    return 'profile';


}





/**


 * @inheritdoc


 */


public function rules() {


    return [


        [['user_id', 'gender_id'], 'required'],


        [['user_id', 'gender_id'], 'integer'],


        [['first_name', 'last_name'], 'string'],


        [['birthdate', 'created_at', 'updated_at'], 'safe'],


        [['gender_id'], 'in', 'range' =&gt; array_keys(&#036;this-&gt;getGenderList())]


        


    ];


}





/**


 * @inheritdoc


 */


public function attributeLabels() {


    return [


        'id' =&gt; 'ID',


        'user_id' =&gt; 'User ID',


        'first_name' =&gt; 'First Name',


        'last_name' =&gt; 'Last Name',


        'birthdate' =&gt; 'Birthdate',


        'gender_id' =&gt; 'Gender ID',


        'created_at' =&gt; 'Created At',


        'updated_at' =&gt; 'Updated At',


        'genderName' =&gt; Yii::t('app', 'Gender'),


        'userLink' =&gt; Yii::t('app', 'User'),


        'profileIdLink' =&gt; Yii::t('app', 'Profile'),


    ];


}





/**


 * @return &#092;yii&#092;db&#092;ActiveQuery


 */


public function getGender() {


    return &#036;this-&gt;hasOne(Gender::className(), ['id' =&gt; 'gender_id']);


}





/**     * behaviors to control time stamp, don't forget to use statement for expression * */


public function behaviors() {


    return [


        'timestamp' =&gt; [


            'class' =&gt; 'yii&#092;behaviors&#092;TimestampBehavior',


            'attributes' =&gt; [


                ActiveRecord::EVENT_BEFORE_INSERT =&gt; ['created_at', 'updated_at'],


                ActiveRecord::EVENT_BEFORE_UPDATE =&gt; ['updated_at'],],


            'value' =&gt; new Expression('NOW()'),


        ],


    ];


}





/**     * uses magic getGender on return statement * */


public function getGenderName() {


    return &#036;this-&gt;gender-&gt;gender_name;


}





/**     * get list of genders for dropdown */


public static function getGenderList() {





    &#036;droptions = Gender::find()-&gt;asArray()-&gt;all();


    return Arrayhelper::map(&#036;droptions, 'id', 'gender_name');


    


}





/**     * @return &#092;yii&#092;db&#092;ActiveQuery */


public function getUser() {


    return &#036;this-&gt;hasOne(User::className(), ['id' =&gt; 'user_id']);


}





/**     * @get Username */


public function getUsername() {


    return &#036;this-&gt;user-&gt;username;


}





/**     * @getUserId */


public function getUserId() {


    return &#036;this-&gt;user ? &#036;this-&gt;user-&gt;id : 'none';


}





/**     * @getUserLink */


public function getUserLink() {


    &#036;url = Url::to(['user/view', 'id' =&gt; &#036;this-&gt;UserId]);


    &#036;options = [];


    return Html::a(&#036;this-&gt;getUserName(), &#036;url, &#036;options);


}





/**     * @getProfileLink */


public function getProfileIdLink() {


    &#036;url = Url::to(['profile/update', 'id' =&gt; &#036;this-&gt;id]);


    &#036;options = [];


    return Html::a(&#036;this-&gt;id, &#036;url, &#036;options);


}

}

[\php]

Any idea why this is happening please?

Thank you,

Ben

its a namespace error




use Yii;

use common\models\User;

use yii\helpers\Url;

use yii\helpers\Html;

use yii\helpers\ArrayHelper;

use yii\db\Expression;

// add this line 

use yii\db\ActiveRecord;



It works thanks!!!