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()) {
//TODO Tosters
//var_dump($news->id);
return Yii::$app->getResponse()->redirect('/news/update/'. $news->id);
}
}
public function actionUpdate()
{
$request = Yii::$app->request;
$get = $request->get();
$model = News::findOne($get['id']);
if ($model->load(Yii::$app->request->post())) {
$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 ($model->status != News::STATUS_ARCHIVE) {
$model->publish_at = (new DateTime())->format('Y-m-d H:i:s');
}
if ($news = $model->create()) {
//TODO Tosters
Yii::$app->getResponse()->redirect('/news');
}
}
return $this->render('update', compact('model'));
}
if ($model->load(Yii::$app->request->post()))
Yii::$app->getResponse()->redirect('/news');
return $this->redirect('/news')
if ($news = $model->create()) {
if ($model->save()) {
// и получить id
$model->id;
(new DateTime())->format('Y-m-d H:i:s');
$model->create()