public function lists($limit = '3') { $search = $this->search; //($_POST['Article']['search'])? $_POST['Article']['search']:($_REQUEST['search'])? $_REQUEST['search']:''; $langs = $this->langs; $query = tblGallery::find()->where('title LIKE :s', [':s' => "%{$search}%"]); if ($langs) { $query->andWhere(['langs' => $langs]); } $query->orderBy('id DESC'); $query->limit($limit); $result = $query->all(); return $result; }
public function actionIndex() { $langs = \app\components\langs::getLang(); $model = new tblGallery(); $query = tblGallery::find()->where(['langs' => $langs, 'published' => 0]); if ($model->load(Yii::$app->request->post())) { $request = Yii::$app->request->post('tblGallery'); $query->andWhere(['amphur' => $request['amphur']]); } $query->orderBy('rand()'); $countQuery = clone $query; $pages = new Pagination(['totalCount' => $countQuery->count(), 'defaultPageSize' => 30]); $list = $query->offset($pages->offset)->limit($pages->limit)->all(); return $this->render('index', ['model' => $model, 'list' => $list, 'pages' => $pages]); }
public function lists($amphur = null, $limit = '3') { $search = $this->search; $langs = $this->langs; //$amphur = $this->amphur; $query = tblGallery::find()->where('title LIKE :s', [':s' => "%{$search}%"]); if ($langs) { $query->andWhere(['langs' => $langs]); } if ($amphur) { $query->andWhere(['amphur' => $amphur]); } $query->orderBy('id DESC'); $query->limit($limit); $result = $query->all(); return $result; }