Answer the question
In order to leave comments, you need to log in
Yii2 How to get the ID of the record I'm working with?
There is a model that creates an entry in the database. Next I have to write. "HOORAY! The $id entry was added successfully"
Here is my controller
public function actionCreate(){
$model = new NewsForm();
$model->create_at = (new DateTime())->format('Y-m-d H:i:s');
$model->update_at = (new DateTime())->format('Y-m-d H:i:s');
if ($news = $model->create()) {
echo 'УРА! Запись' . $model->id . 'была успешно добавлена';
}
}
public function create()
{
if (!$this->validate()) {
return null;
}
$news = new News();
$news->create_at = $this->create_at;
$news->status = 'archive';
var_dump($news);die;
return $news->save() ? $news : null;
}
Answer the question
In order to leave comments, you need to log in
public function create()
{
if (!$this->validate()) {
return null;
}
$news = new News();
$news->create_at = $this->create_at;
$news->status = 'archive';
var_dump($news);die;
return $news->save() ? $news : null;
}
public function actionCreate(){
$model = new NewsForm();
$model->create_at = (new DateTime())->format('Y-m-d H:i:s');
$model->update_at = (new DateTime())->format('Y-m-d H:i:s');
if ($news = $model->create()) {
echo 'УРА! Запись' . $news->id . 'была успешно добавлена';
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question