Viewing file: Main_Controller.inc.php (2.11 KB) -rw-r--r-- Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<?php class Main_Controller{ public static $template; public static function Init() { session_start(); self::$template = new Template('templates/main/index.tpl'); Main_Model::Connect(); Users_Model::UpdateLastAccessDate(); } public static function Run() { $url = $_GET['url']; $parts = explode("/", $url); $class = ucfirst($parts[0]).'_Controller'; $method = ucfirst($parts[1]).'Action'; if ($class === '_Controller' || $parts[0] == 'index' || $parts[0] == 'index.html') $class="Main_Controller"; if (class_exists($class)) { if ($method === 'Action') $method = 'IndexAction'; if (method_exists($class, $method)) { array_shift($parts); array_shift($parts); $arr = $class::$method($parts); if (!empty($arr)) foreach($arr as $key => $value) { self::$template->AddParam($key, $value); } } else self::Error(404); } else self::Error(404); //echo $url; } public static function IndexAction() { return array('Title' => 'Петиції до Житомирської міської ради', 'PageTitle' => 'Петиції до Житомирської міської ради', 'Content' => Main_View::Main().'<h1>Останні петиції</h1>'.List_View::GetLast()); } public static function Error($code) { self::$template = new Template('templates/main/index.tpl'); if ($code == 404) { self::$template->AddParam('Title', 'Сторінку не знайдено'); self::$template->AddParam('Content', ''); Main_Controller::Done(); die; }
} public static function Done() { self::$template->Display(); } public static function Redirect($url) { header("Location: $url"); die; } }
|