Getting unknown property: model::id

Hello all!

I am getting this error:

Exactly this error occurrs in $model->save() line of my controller "actionAdd". This not are a completed method but the idea is it:

[list=1]

[*]Create New Model (ActiveRecord)

[*]Check for post to fill the model

[*]Find related data to save in the fields of the model

[*]Check $model->save(); //Error

[/list]




/**

     * @throws NotFoundHttpException

     */

    public function actionAdd()

    {

        $model = new PgcBuddiesRequest;

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


            //Extraemos la id del usuario a quien se le enviará el mensaje

            $userTo = User::findByUsername($model->invited_username);


            //Controlamos que el usuario exista

            //Controlamos que no seamos nosotros mismos


            $model->inviter_id = Yii::$app->user->identity->id;

            $model->invited_id = $userTo->id;


            /*echo "<br>a" . $model->inviter_id;

            echo "<br>e" . $model->invited_id;

            echo "<br>i" . $model->message;

            die();*/


            if($model->save()){

                Yii::$app->getSession()->setFlash('buddies-add-OK', Yii::t("app", "Page_Buddies_Add_OK"));

            }else{

                Yii::$app->getSession()->setFlash('buddies-add-KO', Yii::t("app", "Page_Buddies_Add_KO"));

            }

            $this->redirect(["buddies/index"]);

        }else{

            throw  new NotFoundHttpException("You do not have permission to stay here.");

        }


    }



How you can see, I tried printing these properties and are good. My activeRecord Model properties list is this:


* @property integer $id

 * @property integer $inviter_id

 * @property integer $invited_id

 * @property integer $created_at

 * @property integer $updated_at

 * @property integer $status

 * @property string $message

Any can help me? Its sure that this model have id property, anyway, I am not using it, I guess that "save()" is using, but this is framework code that are working in more places.

Problem seems to be in your model.

Anyway, you have a bug: you need to return the redirect.

You can see any weird thing?




/**

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

 *

 * @property integer $id

 * @property integer $inviter_id

 * @property integer $invited_id

 * @property integer $created_at

 * @property integer $updated_at

 * @property integer $status

 * @property string $message

 *

 * @property User $invited

 * @property User $inviter

 */

class PgcBuddiesRequest extends \yii\db\ActiveRecord

{

    const STATUS_REQUEST = 1;

    const STATUS_ACCEPTED = 2;

    const STATUS_REJECTED = 3;

    public $invited_username;


    /**

     * @inheritdoc

     */

    public static function tableName()

    {

        return 'pgc_buddies_request';

    }


    /**

     * @inheritdoc

     */

    public function rules()

    {

        return [

            ['status', 'default', 'value' => self::STATUS_REQUEST],


            [['id', 'inviter_id', 'invited_id', 'message'], 'required'],

            [['id', 'inviter_id', 'invited_id', 'created_at', 'updated_at', 'status'], 'integer'],


            ['invited_username', 'filter', 'filter' => 'trim'],

            ['invited_username', 'required', 'message' => Yii::t("app", "Validation_Buddie_Request_Username_Required")],

            ['message', 'string', 'min' => 20, 'max' => 255,

                'message' => Yii::t("app", "Validation_Buddie_Request_Message_Length"),

                'tooLong' => Yii::t("app", "Validation_Buddie_Request_Message_Length_Long"),

                'tooShort' => Yii::t("app", "Validation_Buddie_Request_Message_Length_Short")

            ],


            ['invited_username', 'filter', 'filter' => 'trim'],

            ['invited_username', 'required', 'message' => Yii::t("app", "Validation_Buddie_Request_Username_Required")],

            ['invited_username', 'string', 'min' => 6, 'max' => 255,

                'message' => Yii::t("app", "Validation_Buddie_Request_Username_Length"),

                'tooLong' => Yii::t("app", "Validation_Buddie_Request_Username_Length_Long"),

                'tooShort' => Yii::t("app", "Validation_Buddie_Request_Username_Length_Short")],


            ['message', 'filter', 'filter' => 'trim'],

            ['message', 'required', 'message' => Yii::t("app", "Validation_Buddie_Request_Message_Required")],

            ['message', 'string', 'min' => 20, 'max' => 255,

                'message' => Yii::t("app", "Validation_Buddie_Request_Message_Length"),

                'tooLong' => Yii::t("app", "Validation_Buddie_Request_Message_Length_Long"),

                'tooShort' => Yii::t("app", "Validation_Buddie_Request_Message_Length_Short")

            ],

        ];

    }


    public function behaviors()

    {

        return [

            TimestampBehavior::className(),

        ];

    }


    /**

     * @return \yii\db\ActiveQuery

     */

    public function getInvited()

    {

        return $this->hasOne(PgcUsers::className(), ['id' => 'invited_id']);

    }


    /**

     * @return \yii\db\ActiveQuery

     */

    public function getInviter()

    {

        return $this->hasOne(PgcUsers::className(), ['id' => 'inviter_id']);

    }

}