/** * Finds the Slider model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Slider the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Slider::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
public function actionOrder($id = null, $ordering = null, $direction = null) { if ($id != null || $ordering != null || $direction != null) { $sess = Yii::$app->session->get('sessSlider'); if ($direction == "up") { $newSortOrder = $ordering - 1; } else { if ($direction == "down") { $newSortOrder = $ordering + 1; } } $parent = Slider::findOne($id); $where = array(); $where[] = "ordering = '{$newSortOrder}'"; $where[] = "langs = '" . $parent->langs . "'"; $connection = Yii::$app->db; $sql = "SELECT id FROM tbl_slider " . (count($where) ? "\n WHERE " . implode(' AND ', $where) : ''); $command = $connection->createCommand($sql); $reader = $command->query(); foreach ($reader as $row) { $otherId = $row["id"]; } $where = array(); $where[] = "id = '{$id}'"; $where[] = "langs = '" . $parent->langs . "'"; $sql = 'UPDATE tbl_slider SET ordering = "' . $newSortOrder . '" ' . (count($where) ? "\n WHERE " . implode(' AND ', $where) : ''); $command = $connection->createCommand($sql); $command->execute(); if ($reader->getRowCount() > 0) { $where = array(); $where[] = "id = '{$otherId}'"; $where[] = "langs = '" . $parent->langs . "'"; $sql = 'UPDATE tbl_slider SET ordering = "' . $ordering . '"' . (count($where) ? "\n WHERE " . implode(' AND ', $where) : ''); $command = $connection->createCommand($sql); $command->execute(); } return $this->redirect(['index', 'page' => $_REQUEST['page']]); } }