Пример #1
0
function go()
{
    ob_start();
    require_once LOCAL_PATH . "conf.php";
    require_once LOCAL_PATH . "framework/common/includes.php";
    require_once LOCAL_PATH . "routes.php";
    // parse the requested page, and make it available globally
    if ($_GET["id"] != '') {
        $GLOBALS["REQUEST_PARAMS"] = explode("/", $_GET["id"]);
    } else {
        $GLOBALS["REQUEST_PARAMS"] = array('', '');
    }
    // "/admin/login" gets exploded as { "", "admin", "login" } but it looks better when not rewriting
    // -- so shift off the empty element of the array
    if ($GLOBALS["REQUEST_PARAMS"][0] == "") {
        array_shift($GLOBALS["REQUEST_PARAMS"]);
    }
    if (end($GLOBALS["REQUEST_PARAMS"]) == "") {
        array_pop($GLOBALS["REQUEST_PARAMS"]);
    }
    // take out a prefix, if we're not running from /
    // TODO: remove in order
    function remove_prefix($val)
    {
        return in_array($val, explode("/", ltrim(rtrim(BASEHREF, '/'), '/')));
    }
    if (REWRITE_URLS) {
        array_filter($GLOBALS["REQUEST_PARAMS"], "remove_prefix");
    }
    // display the requested page
    if (!display_page($GLOBALS["REQUEST_PARAMS"])) {
        display_404();
    }
    ob_end_flush();
}
Пример #2
0
 private function handleRequest()
 {
     // We have got the url value from .htaccess, use it to find which page is to be displayed
     $details = $this->getControllerAndMethod();
     $controller_class = $details['controller'] . 'Controller';
     $view_class = $details['controller'] . 'View';
     $controller_method = $details['method'];
     // Check if the page is available in the cache
     $found_cached_page = $this->checkCache();
     if ($found_cached_page == true) {
         return;
     }
     if (class_exists($controller_class)) {
         if (method_exists($controller_class, $controller_method)) {
             if (class_exists($view_class)) {
                 if (method_exists($view_class, $controller_method)) {
                     // Everything is perfect, create the controller and view classes
                     $controller = new $controller_class();
                     $view = new $view_class();
                     // Set the generatrix value in both controller and view so that they can use the other components
                     $controller->setGeneratrix($this);
                     $controller->setView($view);
                     $view->setGeneratrix($this);
                     // Execute the controller
                     $controller->{$controller_method}();
                     $final_page = '';
                     // If the page is running via CLI (Comman Line Interface) don't show the DTD
                     if (!$this->cli->isEnabled() && $controller->isHtml()) {
                         $final_page = addDTD(DTD_TYPE);
                     }
                     // Create the header etc
                     $view->startPage();
                     // Get the final page to be displayed
                     if (version_compare(PHP_VERSION, '5.2.0') >= 0) {
                         $final_page .= $view->{$controller_method}();
                     } else {
                         $html_object = $view->{$controller_method}();
                         if (is_object($html_object)) {
                             $final_page .= $html_object->_toString();
                         }
                     }
                     echo $final_page;
                 } else {
                     display_404('The method <strong>"' . $controller_method . '"</strong> in class <strong>"' . $view_class . '"</strong> does not exist');
                 }
             } else {
                 display_404('The class <strong>"' . $view_class . '"</strong> does not exist');
             }
         } else {
             display_404('The method <strong>"' . $controller_method . '"</strong> in class <strong>"' . $controller_class . '"</strong> does not exist');
         }
     } else {
         //if(!$this->handleCatchAllRequest())
         display_404('The class <strong>"' . $controller_class . '"</strong> does not exist');
     }
 }