コード例 #1
0
ファイル: Adver.php プロジェクト: s-nice/snece
 public static function getDropList()
 {
     $data = Adver::find()->All();
     $dropList = array();
     if ($data) {
         foreach ($data as $key => $row) {
             $dropList[$row['id']] = $row['name'];
         }
     }
     return $dropList;
 }
コード例 #2
0
ファイル: AdverSearch.php プロジェクト: s-nice/snece
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Adver::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, 'create_uid' => $this->create_uid, 'create_at' => $this->create_at, 'update_at' => $this->update_at]);
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'remark', $this->remark]);
     return $dataProvider;
 }
コード例 #3
0
ファイル: AdController.php プロジェクト: s-nice/snece
 /**
  * Updates an existing Ad model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param string $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $model = $this->findModel($id);
     $oldimg = $model->img;
     if ($model->load(Yii::$app->request->post())) {
         $img = UploadedFile::getInstance($model, 'img');
         if ($img) {
             $file = 'upload/' . time() . mt_rand(1, 999) . '.' . $img->extension;
             $img->saveAs($file);
             $model->img = $file;
         } else {
             $model->img = $oldimg;
         }
         if ($model->save()) {
             return $this->redirect(['view', 'id' => $model->id]);
         }
     } else {
         $adverlist = Adver::getDropList();
         return $this->render('update', ['model' => $model, 'adverlist' => $adverlist]);
     }
 }
コード例 #4
0
ファイル: AdverController.php プロジェクト: s-nice/snece
 /**
  * Finds the Adver model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param string $id
  * @return Adver the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Adver::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }