public function logout() { session_start(); session_unset(); $home = new HomeController(); return $home->index(); }
function __construct() { $url = isset($_GET['url']) ? $_GET['url'] : null; $url = rtrim($url, '/'); $url = explode('/', $url); if (empty($url[0])) { require 'Controller/HomeController.php'; $controller = new HomeController(); $controller->index(); return false; } $file = 'Controller/' . ucfirst($url[0]) . 'Controller.php'; if (file_exists($file)) { require $file; } else { throw new Exception("The file: {$file} Does not exists"); } $controller_url = ucfirst($url[0]) . "Controller"; $controller = new $controller_url(); // Carregando o Modelo $controller->loadModel($controller_url); // Verificar se foi especificado um método (action) if (isset($url[2])) { // adicionar parametro no método $controller->{$url[1]}($url[2]); } else { if (isset($url[1])) { $controller->{$url[1]}(); } else { $controller->index(); } } }
public function foundController() { if ($this->url == "home") { $controller = new HomeController(); $controller->index(); } elseif ($this->url == "conversor") { $controller = new ConversorController(); $controller->index(); } }
/** * "Start" the application: * Analyze the URL elements and calls the according controller/method or the fallback */ public function __construct() { // create array with URL parts in $url $this->splitUrl(); // check for controller: no controller given ? then load start-page if (!$this->url_controller) { require APP . 'controller/home.php'; $page = new HomeController(); $page->index(); } elseif (file_exists(APP . 'controller/' . $this->url_controller . '.php')) { // here we did check for controller: does such a controller exist ? // if so, then load this file and create this controller // example: if controller would be "car", then this line would translate into: $this->car = new car(); require APP . 'controller/' . $this->url_controller . '.php'; $controller = ucfirst($this->url_controller) . 'Controller'; $this->url_controller = new $controller(); // check for method: does such a method exist in the controller ? if (method_exists($this->url_controller, $this->url_action)) { if (!empty($this->url_params)) { // Call the method and pass arguments to it call_user_func_array(array($this->url_controller, $this->url_action), $this->url_params); } else { // If no parameters are given, just call the method without parameters, like $this->home->method(); $this->url_controller->{$this->url_action}(); } } else { if (strlen($this->url_action) == 0) { // no action defined: call the default index() method of a selected controller $this->url_controller->index(); } else { header('location: ' . URL . 'error'); } } } else { header('location: ' . URL . 'error'); } }
function publishOne($contentId, $blockId) { include "config/site.php"; $model = new BaseModel(); $home = new HomeController(); //first create news.html $news_file_name = "static/" . $tpl_name . "_news.html"; ob_start(); $home->news(); $news_contents = ob_get_contents(); ob_end_clean(); $fp = fopen($news_file_name, "w"); fwrite($fp, $news_contents); fclose($fp); //$logger = LogUtil::getLogger(); //create a static html for this article $fname = "static/" . $tpl_name . "/" . $contentId . ".html"; //$logger->info($fname); ob_start(); $_GET["id"] = $contentId; $contestIdListStr .= $contentId . ","; $home->info(); $content = ob_get_contents(); ob_end_clean(); $fp = fopen($fname, "w"); fwrite($fp, $content); fclose($fp); //$logger->info("finished"); //create a static html for this article's block $fname = "static/" . $tpl_name . "/b" . $blockId . ".html"; $_GET['block_id'] = $blockId; ob_start(); $home->index(); //php after render ,all mysql connections will be reset $indexContent = ob_get_contents(); ob_end_clean(); $fp = fopen($fname, "w"); fwrite($fp, $indexContent); fclose($fp); //$contentObj = new Content(); //$contentObj->updatePublishSts($contestIdListStr); //create index.html unset($_GET['block_id']); ob_start(); $home->index(); //php after render all mysql connections will be reset $indexContent = ob_get_contents(); ob_end_clean(); $fp = fopen("index.html", "w"); fwrite($fp, $indexContent); fclose($fp); //echo "true"; }
<?php $routes->get('/', function () { HomeController::index(); }); // Auth $routes->get('/login', 'guest', function () { AuthController::login(); }); $routes->post('/login', 'guest', function () { AuthController::handle_login(); }); $routes->get('/logout', 'auth', function () { AuthController::logout(); }); // Profile $routes->get('/profile/edit', 'auth', function () { ProfileController::edit(); }); $routes->post('/profile/update', 'auth', function () { ProfileController::edit(); }); $routes->get('/profile/password', 'auth', function () { ProfileController::password(); }); $routes->post('/profile/password/update', 'auth', function () { ProfileController::updatePassword(); }); // Controlpanel $routes->get('/controlpanel', 'admin', function () { AuthController::controlpanel();
<?php $app = new Slim(); // The following routes are accessed directly via browser $app->get('/', function () { UserHelper::requireProfile(); $controller = new HomeController(); $controller->index(); }); $app->get('/passwd', function () { UserHelper::requireProfile(); $controller = new LoginController(); $controller->passwd(); }); $app->get('/login2', function () { //UserHelper::requireProfile(); $controller = new LoginController(); $controller->login(); }); $app->get('/inbox', function () { UserHelper::requireProfile(); $controller = new MailController(); $controller->inbox(); }); $app->get('/inbox/:id', function ($id) { UserHelper::requireProfile(); $controller = new MailController(); $controller->inbox($id); }); $app->get('/help', function () { //UserHelper::requireProfile();
/** * Aca tenemos que definir todas las rutas que la aplicación va a aceptar. */ public static function init() { // Esta seria la pagina de incio if ($_SERVER['REQUEST_URI'] == '/electiva_php_ude_2015/') { $controller = new HomeController(); $controller->index(); } else { if (strpos($_SERVER['REQUEST_URI'], 'sessions')) { $controller = new SessionsController(); if (strpos($_SERVER['REQUEST_URI'], 'login') && $_SERVER['REQUEST_METHOD'] == 'GET') { $controller->modal(); } else { if (strpos($_SERVER['REQUEST_URI'], 'login') && $_SERVER['REQUEST_METHOD'] == 'POST') { $controller->login(); } else { if (strpos($_SERVER['REQUEST_URI'], 'logout') && $_SERVER['REQUEST_METHOD'] == 'GET') { $controller->logout(); } else { if ($_SERVER['REQUEST_METHOD'] == 'GET') { $controller->index(); } } } } } else { if (strpos($_SERVER['REQUEST_URI'], 'users')) { $controller = new UsersController(); if (strpos($_SERVER['REQUEST_URI'], 'create') && $_SERVER['REQUEST_METHOD'] == 'POST') { $controller->create(); } else { if (strpos($_SERVER['REQUEST_URI'], 'new') && $_SERVER['REQUEST_METHOD'] == 'GET') { $controller->form(); } else { if (strpos($_SERVER['REQUEST_URI'], 'delete') && $_SERVER['REQUEST_METHOD'] == 'GET') { $controller->delete(); } else { if (strpos($_SERVER['REQUEST_URI'], 'modify') && $_SERVER['REQUEST_METHOD'] == 'GET') { $controller->modify(); } else { if (strpos($_SERVER['REQUEST_URI'], 'update') && $_SERVER['REQUEST_METHOD'] == 'POST') { $controller->update(); } else { if ($_SERVER['REQUEST_METHOD'] == 'GET') { $controller->index(); } } } } } } } else { if (strpos($_SERVER['REQUEST_URI'], 'polyclinics')) { $controller = new PolyclinicsController(); if (strpos($_SERVER['REQUEST_URI'], 'create') && $_SERVER['REQUEST_METHOD'] == 'POST') { $controller->create(); } else { if (strpos($_SERVER['REQUEST_URI'], 'new') && $_SERVER['REQUEST_METHOD'] == 'GET') { $controller->form(); } else { if (strpos($_SERVER['REQUEST_URI'], 'delete') && $_SERVER['REQUEST_METHOD'] == 'GET') { $controller->delete(); } else { if ($_SERVER['REQUEST_METHOD'] == 'GET') { $controller->index(); } } } } } else { if (strpos($_SERVER['REQUEST_URI'], 'reports')) { $controller = new ReportsController(); if (strpos($_SERVER['REQUEST_URI'], 'index') && $_SERVER['REQUEST_METHOD'] == 'GET') { $controller->index(); } else { if ($_SERVER['REQUEST_METHOD'] == 'GET') { $controller->index(); } } } else { if (strpos($_SERVER['REQUEST_URI'], 'bookings')) { $controller = new BookingsController(); if (strpos($_SERVER['REQUEST_URI'], 'create') && $_SERVER['REQUEST_METHOD'] == 'POST') { $controller->create(); } else { if (strpos($_SERVER['REQUEST_URI'], 'new') && $_SERVER['REQUEST_METHOD'] == 'GET') { $controller->form(); } else { if (strpos($_SERVER['REQUEST_URI'], 'delete') && $_SERVER['REQUEST_METHOD'] == 'GET') { $controller->delete(); } else { if ($_SERVER['REQUEST_METHOD'] == 'GET') { $controller->index(); } } } } } else { $controller = new HomeController(); $controller->index(); } } } } } } }
<?php abstract class Controller { public $data; function assign($key, $value) { return $this->data[$key] = $value; } function display($file = '') { extract($this->data); if (empty($file)) { $file = "./test.php"; } include $file; } } class HomeController extends Controller { public function index() { $arr = array('age' => '12', 'high' => '170cm'); $this->assign('info', $arr); $this->display(); } } $home = new HomeController(); $home->index();