То есть, если убрать эти правила, то будет выводиться ошибка Отсутствуют обязательные параметры: id
Код: Выделить всё
class Country extends \yii\db\ActiveRecord
{
/**
* @inheritdoc
*/
public static function tableName()
{
return 'country';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['code', 'name'], 'required'],
[['population'], 'integer'],
[['code'], 'string', 'max' => 2],
[['name'], 'string', 'max' => 52],
[['code'], 'unique'],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'code' => 'Code',
'name' => 'Name',
'population' => 'Population',
];
}
}
Код: Выделить всё
public function actionCreate()
{
$model = new Country();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->code]);
}
return $this->render('create', [
'model' => $model,
]);
}