public static function start() { // контроллер и действие по умолчанию $controller_name = 'News'; $action_name = 'Index'; if (!empty($_REQUEST)) { $controller_name = $_REQUEST['controller']; $action_name = $_REQUEST['action']; } // //$routes = explode('/', $_SERVER['REQUEST_URI']); // получаем имя контроллера // if ( !empty($routes[1]) ) // { // $controller_name_base = $routes[1]; // } // // // получаем имя экшена // if ( !empty($routes[2]) ) // { // $action_name = $routes[2]; // } // добавляем префиксы //$model_name = 'Model_'.$controller_name_base; $controller_name = '\\Application\\Controllers\\' . $controller_name; $action_name = 'action' . $action_name; // подцепляем файл с классом модели (файла модели может и не быть) // $model_file = strtolower($model_name).'.php'; // $model_path = "application/models/".$model_file; // if(file_exists($model_path)) // { // include "application/models/".$model_file; // } // // // подцепляем файл с классом контроллера // $controller_file = strtolower($controller_name).'.php'; // $controller_path = "application/controllers/".$controller_file; // if(file_exists($controller_path)) // { // include "application/controllers/".$controller_file; // } // else // { // /* // правильно было бы кинуть здесь исключение, // но для упрощения сразу сделаем редирект на страницу 404 // */ // Route::ErrorPage404(); // } // создаем контроллер $controller = new $controller_name(); $action = $action_name; if (method_exists($controller, $action)) { // вызываем действие контроллера $controller->{$action}(); } else { // здесь также разумнее было бы кинуть исключение Route::ErrorPage404(); } }
static function start() { // controller\action by default $controller_name = 'site'; $action_name = 'Index'; $routes = explode('/', $_SERVER['REQUEST_URI']); // get controller name if (!empty($routes[1])) { $controller_name = $routes[1]; } // get action name if (!empty($routes[2])) { $action_name = $routes[2]; } $controller_name = $controller_name . 'Controller'; $action_name = 'action' . $action_name; $controller_file = $controller_name . '.php'; $controller_path = "controllers/" . $controller_file; if (file_exists($controller_path)) { } else { Route::ErrorPage404(); } $controller_name = "\\controllers\\" . $controller_name; // create object of received controller $controller = new $controller_name(); $action = $action_name; if (method_exists($controller, $action)) { // run action $controller->{$action}(); } else { Route::ErrorPage404(); } }
public static function start() { $routes = explode('/', $_SERVER['REQUEST_URI']); // получим имя контроллера и сделаем первую букву заглавной if ($routes[count($routes) - 2] != "" and isset($routes[count($routes) - 2])) { $controller_name = ucfirst($routes[count($routes) - 2]); } //получим имя действия if ($routes[count($routes) - 1] != "" and isset($routes[count($routes) - 1])) { $action_name = $routes[count($routes) - 1]; } // переопределяем имя контроллера и действия $controller_name = "Controller_" . $controller_name; $action_name = "action_" . $action_name; $controller_file = strtolower($controller_name) . ".php"; $controller_path = "lib/controllers/" . $controller_file; if (file_exists($controller_path)) { include $controller_path; } else { Route::ErrorPage404(); } // создаем экземпляр контроллер $controller = new $controller_name(); $action = $action_name; // вызываем действие контроллера if (method_exists($controller, $action)) { $controller->{$action}(); } else { Route::ErrorPage404(); } }
static function start() { $controller_name = 'news'; $action_name = 'index'; $routes = explode('/', $_SERVER['REQUEST_URI']); if (!empty($routes[1])) { $controller_name = $routes[1]; } if (!empty($routes[2])) { $action_name = $routes[2]; } $model_name = 'Model_' . $controller_name; $controller_name = 'Controller_' . $controller_name; $action_name = 'action_' . $action_name; $model_file = strtolower($model_name) . '.php'; $model_path = "application/models/" . $model_file; if (file_exists($model_path)) { include "application/models/" . $model_file; } $controller_file = strtolower($controller_name) . '.php'; $controller_path = "application/controllers/" . $controller_file; if (file_exists($controller_path)) { include "application/controllers/" . $controller_file; } else { Route::ErrorPage404(); } // создаем контроллер $controller = new $controller_name(); $action = $action_name; if (method_exists($controller, $action)) { $controller->{$action}(); } else { Route::ErrorPage404(); } }
static function start() { $controller_name = 'blog'; $action_name = 'index'; $id = null; $routes = explode('/', $_SERVER['REQUEST_URI']); if (!empty($routes[1])) { $controller_name = $routes[1]; } if (!empty($routes[2])) { $action_name = $routes[2]; } if (!empty($routes[3])) { $id = $routes[3]; } $controller_name = 'Controller_' . $controller_name; $action_name = 'action_' . $action_name; // try { $controller = new $controller_name(); // } catch () { // // } $action = $action_name; if (method_exists($controller, $action)) { if ($id != null) { $controller->{$action}($id); } else { $controller->{$action}(); } } else { Route::ErrorPage404(); exit; } }
static function start() { $controller_name = 'Main'; $action_name = 'index'; $uri = $_SERVER['REQUEST_URI']; $uri = explode('?', $uri); $routes = explode('/', $uri[0]); if (!empty($routes[1])) { $controller_name = $routes[1]; } if (!empty($routes[2])) { $action_name = $routes[2]; } if (isset($_GET['r'])) { $sss = explode('/', $_GET['r']); $controller_name = $sss[0]; $action_name = $sss[1]; } $controller_name = 'Controller_' . $controller_name; $action_name = 'action_' . $action_name; $controller_file = strtolower($controller_name) . '.php'; $controller_path = "application/controllers/" . $controller_file; if (file_exists($controller_path)) { include "application/controllers/" . $controller_file; } else { Route::ErrorPage404(); } $controller = new $controller_name(); $action = $action_name; if (method_exists($controller, $action)) { $controller->{$action}(); } else { Route::ErrorPage404(); } }
static function start() { $controller_name = 'main'; $arg = false; $routes = explode('/', $_SERVER['REQUEST_URI']); // get controller name if (!empty($routes[2])) { $controller_name = $routes[2]; } // get arg if (!empty($routes[3])) { if ($controller_name == "post") { if (!empty($routes[4])) { Route::ErrorPage404(); } else { $arg = $routes[3]; } } else { Route::ErrorPage404(); } } $controller_name = 'Controller_' . $controller_name; // include controller file $controller_file = strtolower($controller_name) . '.php'; $controller_path = "application/controllers/" . $controller_file; if (file_exists($controller_path)) { include "application/controllers/" . $controller_file; } else { Route::ErrorPage404(); } // create a controller $controller = new $controller_name(); $controller->actionIndex($arg); }
static function start() { // контроллер и действие по умолчанию $controller_name = 'Main'; $action_name = 'index'; $routes = explode('/', $_SERVER['REQUEST_URI']); $language = $routes[1]; // получаем имя контроллера if (!empty($routes[2])) { $controller_name = $routes[2]; } // получаем имя экшена if (!empty($routes[3])) { $action_name = $routes[3]; } // получаем аргумент if (!empty($routes[4])) { $id = $routes[4]; } if (isset($_POST['submit']) && !empty($_POST['login']) && !empty($_POST['pass'])) { $login = $_POST['login']; $pass = $_POST['pass']; $log_in = new Model(); $log_in->log_in($login, $pass); } // добавляем префиксы $model_name = 'Model_' . $controller_name; $controller_name = 'Controller_' . $controller_name; $action_name = 'action_' . $action_name; // подцепляем файл с классом модели (файла модели может и не быть) $model_file = strtolower($model_name) . '.php'; $model_path = "application/models/" . $model_file; if (file_exists($model_path)) { include "application/models/" . $model_file; } // подцепляем файл с классом контроллера $controller_file = strtolower($controller_name) . '.php'; $controller_path = "application/controllers/" . $controller_file; if (file_exists($controller_path)) { include "application/controllers/" . $controller_file; } else { /* правильно было бы кинуть здесь исключение, но для упрощения сразу сделаем редирект на страницу 404 */ Route::ErrorPage404(); } $model_language = new Model(); $text = $model_language->language($language); // создаем контроллер $controller = new $controller_name(); $action = $action_name; if (method_exists($controller, $action)) { // вызываем действие контроллера $controller->{$action}($language, $text, $id); } else { // здесь также разумнее было бы кинуть исключение Route::ErrorPage404(); } }
static function start() { // контроллер и действие по умолчанию $controller_name = 'Main'; $action_name = 'index'; $routes = explode('/', $_SERVER['REQUEST_URI']); // получаем имя контроллера if (!empty($routes[4])) { $controller_name = $routes[4]; } // получаем имя экшена if (!empty($routes[5])) { $action_name = $routes[5]; if (substr($routes[5], -4) === ".xml") { $controller_name = "xml"; } if (substr($routes[5], -5) === '.json') { $controller_name = "json"; } } // добавляем префиксы $model_name = 'Model_' . $controller_name; $controller_name = 'Controller_' . $controller_name; $action_name = 'action_' . $action_name; /* echo "Model: $model_name <br>"; echo "Controller: $controller_name <br>"; echo "Action: $action_name <br>"; */ // подцепляем файл с классом модели (файла модели может и не быть) $model_file = strtolower($model_name) . '.php'; $model_path = "models/" . $model_file; if (file_exists($model_path)) { include "models/" . $model_file; } // подцепляем файл с классом контроллера $controller_file = strtolower($controller_name) . '.php'; $controller_path = "controllers/" . $controller_file; if (file_exists($controller_path)) { include "controllers/" . $controller_file; } else { /* правильно было бы кинуть здесь исключение, но для упрощения сразу сделаем редирект на страницу 404 */ Route::ErrorPage404(); } // создаем контроллер $controller = new $controller_name(); $action = $action_name; if (method_exists($controller, $action)) { // вызываем действие контроллера $controller->{$action}(); } else { // здесь также разумнее было бы кинуть исключение Route::ErrorPage404(); } }
static function start() { // контроллер и действие по умолчанию $controller_name = 'Main'; $action_name = 'index'; $params = null; $routes = self::getUri(); $segments = explode('/', $routes); // получаем имя контроллера if (!empty($segments[0])) { $controller_name = array_shift($segments); } // получаем имя экшена if (!empty($segments[0])) { $action_name = array_shift($segments); } $paramSegments = $segments; // добавляем префиксы $model_name = ucfirst($controller_name) . 'Model'; $controller_name = ucfirst($controller_name) . 'Controller'; $action_name = 'action' . ucfirst($action_name); // подцепляем файл с классом модели (файла модели может и не быть) $model_file = $model_name . '.php'; $model_path = "app/models/" . $model_file; if (file_exists($model_path)) { // include "app/models/" . $model_file; } // подцепляем файл с классом контроллера $controller_file = $controller_name . '.php'; $controller_path = "app/controllers/" . $controller_file; if (file_exists($controller_path)) { //include "app/controllers/" . $controller_file; } else { /* правильно было бы кинуть здесь исключение, но для упрощения сразу сделаем редирект на страницу 404 */ Route::ErrorPage404(); } // если контроллер в файле не определен, то выбрасываем 404 if (!class_exists($controller_name)) { Route::ErrorPage404(); } else { $controller = new $controller_name(); $action = $action_name; if (method_exists($controller, $action)) { // вызываем действие контроллера if ($paramSegments) { $controller->{$action}($paramSegments); } else { $controller->{$action}(); } } else { // здесь также разумнее было бы кинуть исключение Route::ErrorPage404(); } } }
/** * makes all routes */ static function start() { $routes = explode('/', $_SERVER['REQUEST_URI']); if (!Authorize::checkAuth() && ($routes[1] != 'register' || $routes[1] == 'langchange')) { // pre-check authorisation if ($routes[1] == 'langchange') { include Module::CONTROLLER_PATH . 'ControllerMain.php'; $controller = new ControllerMain(); $controller->actionlangchange(); } else { include Module::CONTROLLER_PATH . 'ControllerAuth.php'; $controller = new ControllerAuth(); $controller->actionlogin(); } } else { $routeNames = Module::getRoutes(); $controllerName = 'Main'; $actionName = 'index'; // generate controller name if (!empty($routes[1])) { if (isset($routeNames[$routes[1]])) { $controllerName = $routeNames[$routes[1]]['controller']; // get action if (!empty($routes[2])) { $actionName = $routes[2]; } else { $actionName = $routeNames[$routes[1]]['action']; } } else { Route::ErrorPage404(); } } // need for get names with prefixes $modelName = 'Model' . $controllerName; $controllerName = 'Controller' . $controllerName; $actionName = 'action' . ucfirst($actionName); $modelFile = $modelName . Module::DEFAULT_EXT; $modelPath = Module::MODEL_PATH . $modelFile; if (file_exists($modelPath)) { include $modelPath; } $controllerFile = $controllerName . Module::DEFAULT_EXT; $controllerPath = Module::CONTROLLER_PATH . $controllerFile; if (file_exists($controllerPath)) { include $controllerPath; } else { Route::ErrorPage404(); } $controller = new $controllerName(); $action = $actionName; if (method_exists($controller, $action)) { $controller->{$action}(); } else { Route::ErrorPage404(); } } }
static function start() { try { // контроллер и действие по умолчанию $controller_name = 'Main'; $action_name = 'index'; $routes = explode('/', $_SERVER['REQUEST_URI']); // получаем имя контроллера if (!empty($routes[1])) { $controller_name = $routes[1]; } // получаем имя экшена if (!empty($routes[2])) { $action_name = $routes[2]; } // получаем значение дополнительного параметра if (!empty($routes[3])) { $param_val = $routes[3]; } // добавляем префиксы $model_name = 'Model_' . $controller_name; $controller_name = 'Controller_' . $controller_name; $action_name = 'action_' . $action_name; /* echo "Model: $model_name <br>"; echo "Controller: $controller_name <br>"; echo "Action: $action_name <br>"; echo "Parametr: $param_val <br>"; */ // подцепляем файл с классом модели (файла модели может и не быть) $model_file = strtolower($model_name) . '.php'; $model_path = "application/models/" . $model_file; if (file_exists($model_path)) { require_once "application/models/" . $model_file; } // подцепляем файл с классом контроллера $controller_file = strtolower($controller_name) . '.php'; $controller_path = "application/controllers/" . $controller_file; if (file_exists($controller_path)) { require_once "application/controllers/" . $controller_file; } else { throw new Exception('>Путь не найден', 404); } // создаем контроллер $controller = new $controller_name(); $action = $action_name; if (method_exists($controller, $action)) { // вызываем действие контроллера $controller->{$action}($param_val); } else { throw new Exception('>Страница не найдена', 404); } } catch (Exception $e) { if ($e->getCode() == 404) { Route::ErrorPage404(); } } }
static function start() { // контроллер и действие по умолчанию $controller_name = 'Main'; $action_name = 'index'; $routes = explode('/', $_SERVER['REQUEST_URI']); if (count($routes) > 3) { Route::ErrorPage404(); } // получаем имя контроллера if (!empty($routes[1])) { preg_match_all('/([\\w\\d\\.]+)[?]?/i', $routes[1], $matches); $controller_name = $matches[1][0]; } // получаем имя экшена if (!empty($routes[2])) { preg_match_all('/([\\w\\d\\.]+)[?]?/i', $routes[2], $matches); $action_name = $matches[1][0]; } // добавляем префиксы $model_name = 'model_' . $controller_name; $controller_name = 'controller_' . $controller_name; $action_name = 'action_' . $action_name; /* echo "Model: $model_name <br>"; echo "Controller: $controller_name <br>"; echo "Action: $action_name <br>"; */ // подцепляем файл с классом модели (файла модели может и не быть) $model_file = strtolower($model_name) . '.php'; $model_path = "application/models/" . $model_file; if (file_exists($model_path)) { include "application/models/" . $model_file; } // подцепляем файл с классом контроллера $controller_file = strtolower($controller_name) . '.php'; $controller_path = "application/controllers/" . $controller_file; if (file_exists($controller_path)) { include "application/controllers/" . $controller_file; } else { /* правильно было бы кинуть здесь исключение, но для упрощения сразу сделаем редирект на страницу 404 */ Route::ErrorPage404(); } // создаем контроллер $controller = new $controller_name(); $action = $action_name; if (method_exists($controller, $action)) { // вызываем действие контроллера $controller->{$action}(); } else { // здесь также разумнее было бы кинуть исключение Route::ErrorPage404(); } }
static function start() { //контроллер и действие по умолчанию $controller_name = 'Main'; $action_name = 'index'; //$routes = explode('/', substr($_SERVER['REQUEST_URI'], 0, strpos($_SERVER['REQUEST_URI'], "?"))); if (strpos($_SERVER['REQUEST_URI'], "?") == true) { $routes = explode('/', substr($_SERVER['REQUEST_URI'], 0, strpos($_SERVER['REQUEST_URI'], "?"))); } else { $routes = explode('/', $_SERVER['REQUEST_URI']); } //print_r($routes); //die(); //получаем имя контроллера if (!empty($routes[1])) { //$routes[1] = substr($routes[1], 0, strpos($routes[1], "?")); $controller_name = $routes[1]; } //print_r($controller_name); //die(); //получаем имя экшена if (!empty($routes[2])) { $action_name = $routes[2]; } //добавляем префиксы // $model_name = 'Model_' . $controller_name; $controller_name = 'Controller_' . $controller_name; $action_name = 'action_' . $action_name; /*$controller = new $routes[1]; $controller -> load_model($routes[1]);*/ //подключаем файл с классом модели /*$model_file = strtolower($model_name). '.php'; $model_path = "application/models/" . $model_file; if(file_exists($model_path)) { include "application/models/" . $model_file; }*/ //подключаем файл с классом контоллера $controller_file = strtolower($controller_name) . '.php'; $controller_path = "application/controllers/" . $controller_file; if (file_exists($controller_path)) { include "application/controllers/" . $controller_file; } else { Route::ErrorPage404(); } //создаем контроллер $controller = new $controller_name(); $action = $action_name; if (method_exists($controller, $action)) { $controller->{$action}(); //вызываем действие контроллерра } else { Route::ErrorPage404(); // если контроллер запрашиваемой страницы не найден, то переброс на 404 } }
static function start() { // контроллер и действие по умолчанию $controller_name = 'Main'; $action_name = 'index'; $tmp = explode('?', $_SERVER['REQUEST_URI']); $routes = explode('/', $tmp[0]); //$routes = explode('/', $_SERVER['REQUEST_URI']); // получаем имя контроллера if (!empty($routes[1])) { $controller_name = $routes[1]; } // получаем имя экшена if (!empty($routes[2])) { $action_name = $routes[2]; } if (!empty($routes[3])) { $parameters = $routes[3]; } // добавляем префиксы $model_name = 'Model_' . $controller_name; $controller_name = 'Controller_' . $controller_name; $action_name = 'action_' . $action_name; // подцепляем файл с классом модели (файла модели может и не быть) $model_file = strtolower($model_name) . '.php'; $model_path = "models/" . $model_file; if (file_exists($model_path)) { include "models/" . $model_file; } // подцепляем файл с классом контроллера $controller_file = strtolower($controller_name) . '.php'; $controller_path = "controllers/" . $controller_file; if (file_exists($controller_path)) { include "controllers/" . $controller_file; } else { /* правильно было бы кинуть здесь исключение, но для упрощения сразу сделаем редирект на страницу 404 */ Route::ErrorPage404(); } // создаем контроллер //$controller = new $controller_name(); $controller = new $controller_name($parameters); $action = $action_name; if (method_exists($controller, $action)) { // вызываем действие контроллера $controller->{$action}(); } else { // здесь также разумнее было бы кинуть исключение Route::ErrorPage404(); } }
static function start() { // контроллер и действие по умолчанию $controller_name = 'Login'; $action_name = 'index'; $routes = explode('/', $_SERVER['REQUEST_URI']); // получаем имя контроллера if (!empty($routes[1])) { if ($routes[1] === '404') { Route::ErrorPage404(); die; } $controller_name = ucfirst(explode("?", $routes[1])[0]); } // получаем имя экшена if (!empty($routes[2])) { $action_name = $routes[2]; } // добавляем префиксы $model_name = 'Model' . $controller_name; $controller_name = 'Controller' . $controller_name; $action_name = 'action_' . $action_name; // подцепляем файл с классом модели (файла модели может и не быть) $model_file = $model_name . '.php'; $model_path = "application/models/" . $model_file; if (file_exists($model_path)) { include "application/models/" . $model_file; } // подцепляем файл с классом контроллера $controller_file = $controller_name . '.php'; $controller_path = "application/controllers/" . $controller_file; if (file_exists($controller_path)) { include "application/controllers/" . $controller_file; } else { /* правильно было бы кинуть здесь исключение, но для упрощения сразу сделаем редирект на страницу 404 */ //Route::ErrorPage404(); } // создаем контроллер $controller = new $controller_name(); $action = explode("?", $action_name)[0]; if (method_exists($controller, $action)) { //echo $action; // вызываем действие контроллера $controller->{$action}(); } else { // здесь также разумнее было бы кинуть исключение //Route::ErrorPage404(); } }
function GetContent($page, $category) { try { $start = $page * 20 - 20; $this->prepareQuery('SELECT * FROM item WHERE category_id=:category LIMIT :start,20'); // Warning!!! $this->query->bindParam(':start', $start, PDO::PARAM_INT); $this->query->bindParam(':category', $category, PDO::PARAM_INT); return $this->executeQuery_All(); } catch (PDOException $e) { Route::ErrorPage404(); } }
function action_index() { session_start(); /* Для простоты, в нашем случае, проверяется равенство сессионной переменной admin прописанному в коде значению — паролю. Такое решение не правильно с точки зрения безопасности. Пароль должен храниться в базе данных в захешированном виде, но пока оставим как есть. */ if ($_SESSION['admin'] == "12345") { $this->view->generate('admin_view.php', 'template_view.php'); } else { session_destroy(); Route::ErrorPage404(); } }
static function start() { $CONTROLLER = "index"; //main controller $ACTION = "index"; //default action $params = array(); $routes = explode('/', $_SERVER['REQUEST_URI']); /* controller */ if (!empty($routes[1])) { $CONTROLLER = $routes[1]; } /* action */ if (!empty($routes[2])) { $ACTION = $routes[2]; } // get parameters if they exist, else empty array //self::explodeParameters($routes[2]); /* add prefixes */ $model_name = 'model_' . $CONTROLLER; $controller_name = 'controller_' . $CONTROLLER; $action_name = 'action_' . $ACTION; // pick MODEL name and path if it exist $model_file = strtolower($model_name) . '.php'; $model_path = "application/models/" . $model_file; if (file_exists($model_path)) { require_once "application/models/" . $model_file; } else { $model_name = ""; // if controller doesn't have the model } // pick CONTROLLER name and path if it exist $controller_file = strtolower($controller_name) . '.php'; $controller_path = "application/controllers/" . $controller_file; if (file_exists($controller_path)) { require_once "application/controllers/" . $controller_file; // create controller with parameters $controller = new $controller_name($model_name); } else { Route::ErrorPage404(); } if (method_exists($controller, $action_name)) { $controller->{$action_name}(); } else { Route::ErrorPage404(); } }
static function start() { $routes = explode('/', $_SERVER['REQUEST_URI']); $controller_name = 'Main'; // controller by default $action_name = 'index'; // action by default /*if (strpos($_SERVER['REQUEST_URI'], 'main/validate')) { $action_name = 'validate'; } else { $action_name = 'index'; // action by default }*/ // gets controller name if (!empty($routes[2])) { $controller_name = $routes[2]; } // gets action name if (!empty($routes[3])) { $action_name = $routes[3]; } // prefix adding $model_name = 'Model_' . $controller_name; $controller_name = 'Controller_' . $controller_name; $action_name = 'action_' . $action_name; // gets model file (if exists) $model_file = strtolower($model_name) . '.php'; $model_path = "models/" . $model_file; if (file_exists($model_path)) { include "models/" . $model_file; } // gets controller file (if exists) $controller_file = strtolower($controller_name) . '.php'; $controller_path = "controllers/" . $controller_file; if (file_exists($controller_path)) { include "controllers/" . $controller_file; } else { Route::ErrorPage404(); } // creates a controller $controller = new $controller_name(); $action = $action_name; if (method_exists($controller, $action)) { $controller->{$action}(); } else { Route::ErrorPage404(); } }
static function start() { //default controller and action $controller_name = "Main"; $action_name = "Index"; if (isset($_GET['route'])) { $route = $_GET['route']; } else { $route = ''; } $routes = explode('/', $route); var_dump($routes); //get controller name if (!empty($routes[0])) { $controller_name = ucfirst(array_shift($routes)); } if (!empty($routes[1])) { $action_name = ucfirst(ucfirst(array_shift($routes))); } //add prefixes $model_name = 'Model_' . $controller_name; $controller_name = 'Controller_' . $controller_name; $action_name = 'action' . $action_name; //connect model file $model_file = $model_name . '.php'; $controller_file = $controller_name . '.php'; $model_path = "application/models/" . $model_file; if (file_exists($model_path) && is_file($model_path) && is_readable($model_path)) { include 'application/models/' . $model_path; } //connect class file $controller_path = "application/controllers/" . $controller_file; if (file_exists($controller_path) && is_file($controller_path) && is_readable($controller_path)) { include "application/controllers/" . $controller_file; } else { Route::ErrorPage404(); } //creating controller class $controller = new $controller_name(); $action = $action_name; if (method_exists($controller_name, $action_name)) { //call the method $controller->{$action}(); } else { Route::ErrorPage404(); } }
function action_editnews($id) { if ($this->model->get_rights() & U_EDIT) { $data["news"] = $this->model->viewnews($id['0']); $data["login"] = $this->model->get_login(); if (isset($_POST['submit'])) { if (is_uploaded_file($_FILES['uploadfile']['tmp_name'])) { move_uploaded_file($_FILES['uploadfile']['tmp_name'], 'images/' . $_FILES['uploadfile']['name']); } $this->model->editnews($this->addnews($id['0'])); header("Location: /news"); } $this->view->generate('edit_news_view.php', 'template_view.php', $data); } else { Route::ErrorPage404(); } }
static function start() { // default controller and cation $controller_name = 'Main'; $action_name = 'index'; $routes = explode('/', $_SERVER['REQUEST_URI']); // Get controller name if (!empty($routes[1])) { $controller_name = $routes[1]; } // Get action name if (!empty($routes[2])) { $action_name = $routes[2]; } // Add prefix $model_name = 'Model_' . $controller_name; $controller_name = 'Controller_' . $controller_name; $action_name = 'action_' . $action_name; // Try to load a class of model $model_file = strtolower($model_name) . '.php'; $model_path = "app/models/" . $model_file; // if the model is not exist if (file_exists($model_path)) { include "app/models/" . $model_file; } // Try to load a class of controller $controller_file = strtolower($controller_name) . '.php'; $controller_path = "app/controllers/" . $controller_file; if (file_exists($controller_path)) { include "app/controllers/" . $controller_file; } else { // if controller is not found Route::ErrorPage404(); } // Create instance of controller $controller = new $controller_name(); $action = $action_name; if (method_exists($controller, $action)) { // Execute action $controller->{$action}(); } else { // if action in not found Route::ErrorPage404(); } }
static function start() { // контроллер и действие по умолчанию $controller_name = 'Main'; $action_name = 'index'; $routes = explode('/', $_SERVER['REQUEST_URI']); // получаем имя контроллера if (!empty($routes[1]) && $routes[1] != 'index.php') { $controller_name = $routes[1]; } // получаем имя экшена if (!empty($routes[2])) { $action_name = $routes[2]; } // добавляем префиксы $model_name = 'Model_' . $controller_name; $controller_name = 'Controller_' . $controller_name; $action_name = 'action_' . $action_name; // подцепляем файл с классом модели (файла модели может и не быть) $model_file = strtolower($model_name) . '.php'; $model_path = "models/" . $model_file; if (file_exists($model_path)) { include "models/" . $model_file; } // подцепляем файл с классом контроллера $controller_file = strtolower($controller_name) . '.php'; $controller_path = "controllers/" . $controller_file; if (file_exists($controller_path)) { include "controllers/" . $controller_file; } else { Route::ErrorPage404(); } // создаем контроллер $controller = new $controller_name(); $action = $action_name; if (method_exists($controller, $action)) { // вызываем действие контроллера $controller->{$action}(); } else { Route::ErrorPage404(); } }
public function get_news() { if (!empty(Route::$routes[2])) { $action = strtolower(Route::$routes[2]); } else { $action = 'index'; } $count_news = $this->db->get_elements($this->sql_get_count_news); $count_news = $count_news[0]['count_news']; switch ($action) { case 'index': //если не был прописан экшен, подгатавливаем url для работы с постраничной навигацией Route::$routes[] = 'list'; //Вывод списка новостей //Вывод списка новостей case 'list': if (!empty(Route::$routes[3])) { $navigate_start = (int) Route::$routes[3]; } else { $navigate_start = 0; } $news = $this->db->get_elements($this->sql_get_news_list, array('start' => $navigate_start, 'limit' => $this->news_limit)); $news['mode'] = 'list'; //Говорим представлению о том, что нужно выводить список $news['navigate'] = $this->getPageNavigation($count_news, $this->news_limit, $navigate_start, $this->link_limit); break; //Чтение одной новости //Чтение одной новости case 'read': if (!empty(Route::$routes[3])) { $news_id = (int) Route::$routes[3]; } $news = $this->db->get_elements($this->sql_get_news, array('news_id' => $news_id)); $news['mode'] = 'read'; //Говорим представлению о том, что нужно прочитать конкретную новость $this->db->sql_execute($this->sql_incriment_views, array('news_id' => $news_id)); break; default: Route::ErrorPage404(); } return $news; }
static function start() { $controller_name = 'Main'; // Контроллер по умолчанию $action_name = 'index'; // Действие по умолчанию $routes = explode('/', $_SERVER['REQUEST_URI']); // получаем имя контроллера if (!empty($routes[1])) { $controller_name = $routes[1]; } // получаем имя действия if (!empty($routes[2])) { $action_name = $routes[2]; } // добавляем префиксы $model_name = 'Model_' . $controller_name; $controller_name = 'Controller_' . $controller_name; $action_name = 'action_' . $action_name; // подключаем файл с классом модели (файла модели может и не быть) $model_file = strtolower($model_name) . '.php'; $model_path = 'application/models/' . $model_file; if (file_exists($model_path)) { include $model_path; } // Подключение файла с классом контроллера $controller_file = strtolower($controller_name) . '.php'; $controller_path = 'application/controllers/' . $controller_file; if (file_exists($controller_path)) { include $controller_path; } else { Route::ErrorPage404(); } //Создаём контроллер $controller = new $controller_name(); $action = $action_name; if (method_exists($controller, $action)) { $controller->{$action}(); } else { Roure::ErrorPage404(); } }
static function start() { //контроллер и действие по умолчанию $controller_name = 'Register'; $action_name = 'index'; $routes = explode("/", $_SERVER['REQUEST_URI']); $routes = explode("?", $_SERVER['REQUEST_URI']); //получение имени контроллера и эешена if (!empty($routes[1])) { $controller_name = $routes[1]; } if (!empty($routes[2])) { $action_name = $routes[2]; } // добавляем префиксы $model_name = 'Model_' . $controller_name; $controller_name = 'Controller_' . $controller_name; $action_name = 'action_' . $action_name; //подключение файл с классом модели (файла модели может и не быть) $model_file = strtolower($model_name) . '.php'; $model_path = "application/models/" . $model_file; if (file_exists($model_path)) { include "application/models/" . $model_file; } //файл с классом контроллера $controller_file = strtolower($controller_name) . '.php'; $controller_path = "application/controllers/" . $controller_file; if (file_exists($controller_path)) { include "application/controllers/" . $controller_file; } else { Route::ErrorPage404(); } //создаем контроллер $controller = new $controller_name(); $action = $action_name; if (method_exists($controller, $action)) { $controller->{$action}(); } else { Route::ErrorPage404(); } }
static function start() { $controller_name = 'main'; $action_name = 'index'; $routes = explode('/', $_SERVER['REQUEST_URI']); // get controller name if (!empty($routes[2])) { $controller_name = $routes[2]; } // get method name if (!empty($routes[3])) { $action_name = $routes[3]; } // add prefixes $model_name = 'Model_' . $controller_name; $controller_name = 'Controller_' . $controller_name; $action_name = 'action_' . $action_name; // include model file (can no exist) $model_file = strtolower($model_name) . '.php'; $model_path = "application/models/" . $model_file; if (file_exists($model_path)) { include "application/models/" . $model_file; } // include mcontroller file $controller_file = strtolower($controller_name) . '.php'; $controller_path = "application/controllers/" . $controller_file; if (file_exists($controller_path)) { include "application/controllers/" . $controller_file; } else { Route::ErrorPage404(); } // create a controller $controller = new $controller_name(); $action = $action_name; if (method_exists($controller, $action)) { // run controller method $controller->{$action}(); } else { Route::ErrorPage404(); } }
function action_category($routes) { if ($routes[0] == "page" && preg_match("/^[0-9]{1,6}\$/", $routes[1]) && preg_match("/^[0-9]{1,6}\$/", $routes[2])) { $files = $this->get_files_array(array('content_menu_style.css', 'menu_without_animation.js', 'content_style.css', 'content_animation_description.js', 'animation_three_level.js', 'add_cart.js')); $files['menu']['file'] = 'content_menu_view.php'; $count = $this->model->GetCount($routes[1]); $data = array(); $data['item'] = $this->model->GetContent($routes[2], $routes[1]); $data['authorization'] = $this->model->mainApproveLogin(); $data['menu_items'] = $this->model->get_menu_items(); $data['number_of_pages'] = $count[0]; $data['category'] = $routes[1]; $data['current_page'] = $routes[2]; $data['cart'] = $this->model->get_count(); $this->view->generate('content_view.php', 'template_view.php', $files, $data); //$this->model->delete_node(2,'mexican'); //$this->model->create_node(3,'testoviyfrUkT','apple1'); } else { Route::ErrorPage404(); } }
static function start() { $controller_name = 'Main'; $action_name = 'index'; $routes = explode('/', $_SERVER['REQUEST_URI']); if (!empty($routes[1])) { $controller_name = $routes[1]; } // get action name if (!empty($routes[2])) { $action_name = $routes[2]; } //get additional params $aParam = []; if (!empty($routes[3])) { $aParam = array_slice($routes, 3); } $model_name = 'Model_' . $controller_name; $controller_name = 'Controller_' . $controller_name; $action_name = 'action_' . $action_name; $model_file = strtolower($model_name) . '.php'; $model_path = "application/models/" . $model_file; if (file_exists($model_path)) { include "application/models/" . $model_file; } $controller_file = strtolower($controller_name) . '.php'; $controller_path = "application/controllers/" . $controller_file; if (file_exists($controller_path)) { include "application/controllers/" . $controller_file; } else { Route::ErrorPage404(); } $controller = new $controller_name(); $action = $action_name; if (method_exists($controller, $action)) { $controller->{$action}($aParam); } else { Route::ErrorPage404(); } }