Ejemplo n.º 1
0
/**
 * Find all products that should be rendered on the page provided in arguments
 * Create pagination variables
 * Render view provided in arguments
 * This action currently used in /list route and ajax-list route
 *
 * @param integer $page
 * @param string $view
 * @param array $arguments
 */
function product_list($page, $view, $arguments = [])
{
    if (!is_numeric($page)) {
        renderNotFound();
    }
    $products = pageQuery($page, $arguments);
    $last = end($products);
    $first = $products[0];
    $next = product_make_pager_link($page, $arguments, $last);
    if (intval($page) > 1) {
        $previous = product_make_pager_link($page, $arguments, $first, LINK_PREV);
    } else {
        $previous = false;
    }
    include $view;
}
Ejemplo n.º 2
0
/**
 * Get request URIm compare to existing routes
 * Calls route dispatcher and binds parameter to it if it was found
 */
function handleRoute()
{
    global $routes;
    if ($_SERVER['REQUEST_METHOD'] !== 'POST' && $_SERVER['REQUEST_METHOD'] !== 'GET') {
        methodNotAllowed();
    }
    foreach ($routes as $route => $dispatcher) {
        $match = routeMatchParts($route, $_SERVER['REQUEST_URI']);
        if ($match === true) {
            callRoute($dispatcher);
            return;
        } elseif ($match !== false) {
            callRouteWithParam($dispatcher, str_replace('?' . $_SERVER['QUERY_STRING'], '', $match));
            return;
        }
    }
    renderNotFound();
}