public function actionAddcity() { $form = new AddCity(); if ($form->load(Yii::$app->request->post()) && $form->validate()) { $city = new Top(); $city->title = $form->title; $form->img = UploadedFile::getInstance($form, 'img'); $form->img->saveAs('image/city/' . $form->img->baseName . '.' . $form->img->extension); $city->img = $form->img->baseName . '.' . $form->img->extension; $city->about = $form->about; $city->date = time(); $city->save(); return $this->refresh(); } return $this->render('addcity', ['form' => $form]); }
public function actionCities() { $query = Top::find(); $pagination = new Pagination(['defaultPageSize' => 5, 'totalCount' => $query->count()]); $top = $query->orderBy('views DESC')->offset($pagination->offset)->limit($pagination->limit)->all(); return $this->render('cities', ['top' => $top, 'pagination' => $pagination]); }
public function run() { $query = Top::find(); $top = $query->orderBy('views DESC')->limit(6)->all(); return $this->render('top', ['top' => $top]); }