public function navigate() { $url = trim($_SERVER['REQUEST_URI'], "/"); $result = $this->findUrl($url); $urlParts = explode("/", $url); $args = array(); if ($result) { // Если URL записан. $parts = explode("/", $result); } else { $parts = $urlParts; } $controller = ucfirst(array_shift($parts)) . "Controller"; if (!class_exists($controller)) { Error::httpError(404); } $controller = new $controller(); $action = "action" . ucfirst(array_shift($parts)); if (!method_exists($controller, $action)) { Error::httpError(404); } if (method_exists($controller, "access")) { $controller->access(); } for ($i = 0; $i < count($parts); $i++) { $args[] = array_pop($urlParts); } call_user_func_array(array(new $controller(), $action), $args); exit; }
public function access() { if (!Auth::isLogged()) { $this->redirect("/login"); } if (!Auth::isAdmin()) { Error::httpError(403); } }
public function actionIndex($seo) { $cat = CatsModel::model()->where("`seo_url`='{$seo}'")->findRow(); if (!$cat) { Error::httpError(404); } $movies = MoviesModel::model()->where("`cat_id`='{$cat->id}'")->findAll(); $this->view("category/list", array("movies" => $movies, "cat" => $cat), false); }
$_SESSION['error_' . $name] = $text; } /* * Проверяем, есть ли в сессии глобальная ошибка. */ public static function haveGlobal($name) { return isset($_SESSION['error_' . $name]); } /* * Получаем глобальную ошибку и стираем её. */ public static function showGlobal($name) { $error = isset($_SESSION['error_' . $name]) ? $_SESSION['error_' . $name] : false; unset($_SESSION['error_' . $name]); return $error; } /* * Отображаем страницу ошибки. */ public static function httpError($name, $isShow = true) { if ($isShow === true) { include "views/errors/" . $name . ".php"; exit; } } } Error::httpError("error", false);
public function actionActivate($hash) { $model = UsersModel::model()->where("`hash`='{$hash}'")->findRow(); if (!$model || $model->status != 0) { Error::httpError(404); } $model->status = 1; $model->save(); $this->view("user_registered", array("message" => Lang::get("account_activated")), false); }
public function actionShowSerial($seoUrl) { if ($_SESSION['user']['id'] != "") { $movie = MoviesModel::model()->where("`seo_url` = '{$seoUrl}'")->findRow(); $seasons = SeasonModel::model()->where("`serial_id` = '{$movie->id}'")->order("sort asc")->findAll(); $rating = RatingsModel::getRating($movie->id); $rating_count = RatingsModel::getRatingCount($movie->id); $user = UsersModel::model()->where(" `id` = '{$_SESSION['user']['id']}' ")->findRow(); $user_major = UsersModel::isPackageActive(); switch ($movie->in_roles) { case 1: $difficulty = "Легкий"; break; case 2: $difficulty = "Легкий-средний"; break; case 3: $difficulty = "Средний"; break; case 4: $difficulty = "Средний-сложный"; break; case 5: $difficulty = "Сложный"; break; default: $difficulty = $movie->in_roles; } if (!$movie) { Error::httpError(404); } $this->view("movies/serial_show", array("movie" => $movie, "seasons" => $seasons, "rating" => $rating, "rating_count" => $rating_count, "difficulty" => $difficulty, "user" => $user, "user_major" => $user_major), false); } else { $this->redirect("/"); } }