Ejemplo n.º 1
0
 public function actionUpdate($id = null)
 {
     $cid = Yii::$app->getRequest()->getQueryParam('cid');
     $model = new TblGuides();
     if ($model->load($_POST)) {
         $id = $_POST['TblGuides']['id'];
         if ($id) {
             $model = TblGuides::findOne($id);
             $model->attributes = $_POST['TblGuides'];
         }
         if ($model->save()) {
             return $this->redirect(array('index', 'cid' => $model->cid));
         } else {
             print_r($model->getErrors());
             exit;
         }
     }
     if ($id) {
         $model = TblGuides::findOne($id);
     } else {
         $sess = Yii::$app->session->get('sessTblGuides');
         $model->langs = $sess['langs'];
         $model->cid = $cid ? $cid : $sess['cid'];
     }
     return $this->render('update', ['model' => $model]);
 }
Ejemplo n.º 2
0
 public function actionIndex($cid = 1)
 {
     $search = new TblGuides();
     $langs = \app\components\langs::getLang();
     $query = TblGuides::find()->where(['cid' => $cid, 'langs' => $langs, 'published' => 1]);
     $amp = Yii::$app->getRequest()->getQueryParam('amp');
     if ($amp) {
         $query->andWhere(['amphur' => $amp]);
     }
     if ($search->load(Yii::$app->request->post())) {
         $request = Yii::$app->request->post('TblGuides');
         $s = $request['search'];
         //$query->orWhere([['LIKE', 'titls', "%$s%"],['LIKE', 'fulltexts', "%$s%"]]);
         //$query->orWhere('LIKE', 'titles', "%$s%");
         $query->andFilterWhere(['or', ['like', 'titles', $s], ['like', 'fulltexts', $s]]);
     }
     $query->orderBy('rand()');
     $countQuery = clone $query;
     $pages = new Pagination(['totalCount' => $countQuery->count(), 'defaultPageSize' => 10]);
     $list = $query->offset($pages->offset)->limit($pages->limit)->all();
     return $this->render('index', ['search' => $search, 'model' => $list, 'cid' => $cid, 'pages' => $pages]);
 }