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 actionUpdate($id = null) { $model = new tblGallery(); if ($model->load($_POST)) { $id = $_POST['tblGallery']['id']; if ($id) { $model = tblGallery::findOne($id); $model->attributes = $_POST['tblGallery']; } if ($model->save()) { return $this->redirect(['index', 'langs' => $_POST['tblGallery']['langs']]); } else { print_r($model->getErrors()); exit; } } if ($id) { $model = tblGallery::findOne($id); } else { $model->langs = $_REQUEST['langs']; } return $this->render('update', ['model' => $model]); }
public function actionUpdate($id = null) { $model = new tblGallery(); if ($model->load(Yii::$app->request->post())) { $request = Yii::$app->request->post('tblGallery'); $id = $request['id']; if ($id) { $model = tblGallery::findOne($id); $model->attributes = $request; } if ($model->save()) { return $this->redirect(['index', 'langs' => $request['langs']]); } else { print_r($model->getErrors()); exit; } } if ($id) { $model = tblGallery::findOne($id); } else { $model->langs = \Yii::$app->getRequest()->getQueryParam('langs'); } return $this->render('update', ['model' => $model]); }