예제 #1
0
 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]);
 }
예제 #2
0
 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]);
 }
예제 #3
0
파일: TopWidget.php 프로젝트: HAJIOM/yii2
 public function run()
 {
     $query = Top::find();
     $top = $query->orderBy('views DESC')->limit(6)->all();
     return $this->render('top', ['top' => $top]);
 }