Beispiel #1
0
<?php

define("APPLICATION", __DIR__);
define("ROOT", __DIR__ . "/..");
define("WEBROOT", ROOT . "/public");
define("LIBRARY", ROOT . "/library");
ini_set("display_errors", 1);
ini_set("error_reporting", E_ALL | E_STRICT);
session_start();
ob_start();
/**
 * Autoloading
 */
require_once LIBRARY . "/WebFW/Loader.php";
$loader = WebFW\Loader::getInstance();
$loader->addNamespaces(array("SampleApp" => APPLICATION, "WebFW" => LIBRARY . "/WebFW"));
$loader->register();
/**
 * Setup
 */
WebFW\View::$defaultPath = APPLICATION . "/views/";
WebFW\Registry::set("layout", new WebFW\View("layout.php"));
Beispiel #2
0
use WebFW\Router\Route;
try {
    require __DIR__ . "/../application/bootstrap.php";
    $routes = array("index-name" => new Route("/:name", array("controller" => "SampleApp\\Controller\\IndexController", "action" => "indexAction"), array(":name" => ".+")), "index" => new Route("/", array("controller" => "SampleApp\\Controller\\IndexController", "action" => "indexAction")));
    $router = new WebFW\Router($routes);
    $route = $router->match($_SERVER["REQUEST_URI"]);
    WebFW\Registry::set("router", $router);
    if ($route) {
        $controllerName = $route->getControllerName();
        $controller = new $controllerName();
        $controller->setRoute($route);
        if (WebFW\Registry::exists("layout")) {
            $controller->setLayout(WebFW\Registry::get("layout"));
        }
        echo $controller->dispatch($route->getActionName(), $route->getVariables());
    } else {
        throw new Exception("File not found", 404);
    }
} catch (Exception $e) {
    switch ($e->getCode()) {
        case 404:
            WebFW\Registry::get("layout")->content = new WebFW\View("404.php");
            echo WebFW\Registry::get("layout");
            break;
        default:
            echo "<h1>Error</h1><p>{$e->getMessage()}</p>";
            echo "<pre>{$e->getTraceAsString()}</pre>";
            break;
    }
}