我有问题。假设我们有这样一个模型:保存表单资料Yii2
/**
* This is the model class for table "user".
*
* @property integer $id
* @property string $username
* @property string $first_name
* @property string $last_name
*/
class User extends \yii\db\ActiveRecord
{
public static function tableName()
{
return 'user';
}
public function rules()
{
return [
// some rules for fields
];
}
public function attributeLabels()
{
return [
// some attributes
];
}
现在我想创建更新表单模型(例如)first_name。所以我创建了下一个表单模型:
class UpdateUserFirstNameForm extends Model
{
public $first_name
public function rules()
{
return [
// some rules for first_name
];
}
问题是 - 我如何保存这个表单?我必须写在控制器中?
你'user'表,有一个名为场'first_name'? – gmc
是的,当然。你可以在@property中看到用户模型 –