Answer the question
In order to leave comments, you need to log in
Error loading data from $_POST array to model?
Hello! After loading data from $_POST array Loading data via $model->load(Yii::$app->request->post()) there was a problem. After loading the data, the id_sec and is_show attributes are filled with the old data, although Yii::$app->request->post() contains new data, you have to write such a crutch
$model->id_sec = Yii::$app->request-> post("News")["id_sec"];
$model->is_show = Yii::$app->request->post("News")["is_show"];
Tell me how to solve the problem without using a crutch?
Answer the question
In order to leave comments, you need to log in
I suspect that you do not have these attributes in the rules, you need to at least specify safe
Add a check for the id_sec, is_show properties to the rules rules and delete these two lines
$model->id_sec = Yii::$app->request->post("News")["id_sec"];
$model->is_show = Yii::$app->request->post("News")["is_show"];
$model->created_at = time();
$model->count_show = 0;
$model->count_clicks = 0;
$model->is_news = 1;
public function behaviors()
{
return [
TimestampBehavior::className()
];
}
$model->created_at = time();
['cout_show', 'count_click'], 'default', 'value' => 0]
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question