public function actionIndex() { $model = new GuestBook(); $guest_row = $model->find()->all(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->refresh(); } else { return $this->render('index', ['model' => $model, 'guest_row' => $guest_row]); } }
public function actionIndex() { //$page = new Pages(); $news = News::find()->where(['status' => '1'])->orderBy('id DESC')->limit(4)->all(); $guest = GuestBook::find()->where(['status' => '1'])->orderBy('id DESC')->limit(4)->all(); $pages = Pages::find()->where(['page' => 'home'])->one(); return $this->render('index', ['page' => $pages, 'news' => $news, 'guest' => $guest]); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = GuestBook::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'parent_id' => $this->parent_id, 'created_at' => $this->created_at, 'status' => $this->status]); $query->andFilterWhere(['like', 'username', $this->username])->andFilterWhere(['like', 'email', $this->email])->andFilterWhere(['like', 'message', $this->message]); return $dataProvider; }
/** * Finds the GuestBook model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return GuestBook the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = GuestBook::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }