我需要覆盖默认的Profile模型。我已经设法添加了我需要的字段,但是从那以后我就有了一些东西。在插入和更新时,这些字段不会更新到数据库。
我已经创建了必要的迁移,所以我已经在数据库中有这些字段
我缺少什么>见下面我的app / models / Profile.php
<?php
namespace app\models;
/**
* Description Profile
*
* This form @overrides dektrium\user\models\Profile
*/
use dektrium\user\models\Profile as BaseProfile;
use yii\web\UploadedFile;
use Yii;
use dektrium\user\models\User;
class Profile extends BaseProfile {
/**
* public variables to be added to the model
*/
public $profile_pic;
public $expertise_id;
public $country_id;
public function rules() {
$rules = parent::rules();
$rules['profile_pic'] = ['profile_pic', 'file'];
$rules['expertise_id'] = ['expertise_id', 'integer'];
$rules['country_id'] = ['country_id', 'integer'];
return $rules;
}
/**
* @inheritdoc
*/
public function attributeLabels() {
$labels = parent::attributeLabels();
$labels['profile_pic'] = \Yii::t('user', 'Profile Picture');
$labels['bio'] = \Yii::t('user', 'Biography');
$labels['expertise_id'] = \Yii::t('user', 'Expertise');
$labels['country_id'] = \Yii::t('user', 'Country');
return $labels;
}
}
答案 0 :(得分:3)
首先,删除这一行:
public $profile_pic;
public $expertise_id;
public $country_id;
如果您已在表格中添加了这些字段,则无需声明它们。如您所见,其他任何属性都没有被声明。这已经通过从ActiveRecord
扩展模型并声明tableName