Yii2 active record model not saving data

后端 未结 7 651
情话喂你
情话喂你 2020-12-16 17:47

I\'ve built a simple form model & view, a simple AR model, and a simple controller. The form model assigns the correct values to the AR instance, but when I call save(),

相关标签:
7条回答
  • 2020-12-16 18:31

    Okay, I figured it out. Turns out that if you declare public attributes in your ActiveRecord model, they obscure the automatic attributes that are created by AR. Data gets assigned to your obscuring attributes but doesn't get sent into the database.

    The correct AR model should have been simply this:

    <?php
    
    namespace app\models;
    
    use Yii;
    use yii\db\ActiveRecord;
    
    class Prompt extends ActiveRecord
    {
        /**
         * @return string the name of the table associated with this ActiveRecord class.
         */
        public static function tableName()
        {
            return 'prompt';
        }
    }
    
    0 讨论(0)
提交回复
热议问题