Yii attemps to save non-db attribute

As in the topic - Yii tries to save attribute that is abstract thus throwing an error. There is not much going on in the code, I have added it to attributes() and created getter and setter





    public function attributes() {

        return array_merge(

            parent::attributes(),

            ['fliLabel']

        );

    }

    

    public function setFliLabel($value) {

        $this->fliLabel = $value;

    }


    public function getFliLabel() {

        return $this->fliLabel;

    }



It is even more confusing as in this issue Qiang says "QueryBuilder ensures only table columns are being inserted/updated."

It seems that statement of Qiang’s is not fully correct.

Try this code:




    public $fliLabel;

    

    public function setFliLabel($value) {

        $this->fliLabel = $value;

    }


    public function getFliLabel() {

        return $this->fliLabel;

    }



Validation will work on fields as well.

It solves problem of saving it to db but I want to be able to set this attribute using setAttributes() and in your example this will not work.

Only need 2 steps:

  • add public attribute

  • add a rule for validation