public function actionGuestBook() { $model = new GuestBook(); if ($model->load(Yii::$app->request->post()) && Yii::$app->session->get('guestbook') == 'Verification') { Yii::$app->session->set('guestbook', 'success'); Yii::$app->session->setFlash('success', 'Сообщение добавлено в гостевую книгу.'); $model->created_at = date("Y-m-d H:i:s"); $model->save(false); return $this->redirect(['guest-book']); } $allItems = GuestBook::find()->where('on_off=0')->orderBy('created_at DESC')->all(); return $this->render('guestbook', ['model' => $model, 'allItems' => $allItems]); }
public function create_data($data) { $obj = new GuestBook(); $obj->attributes = $data; return $obj->save(); }