Aura.Router can also be used as a micro-framework dispatcher!

Sometimes you may wish to use Aura as a micro-framework. It’s also possible to assigning anonymous function to controller:

<?php
$map->add("read", "/blog/read/{:id}{:format}", [
    "params" => [
        "id" => "(d+)",
        "format" => "(..+)?",
    ],
    "values" => [
        "controller" => function ($args) {
            $id = (int) $args["id"];
            return "Reading blog ID {$id}";
        },
        "format" => ".html",
    ],
));

When you are using Aura.Router as a micro-framework, the dispatcher will look something similar to the one below:

<?php
$params = $route->values;
$controller = $params["controller"];
unset($params["controller"]);
echo $controller($params);

Via phpmaster | Web Routing in PHP with Aura.Router. The Aura project for PHP 5.4 codebase is here.

One thought on “Aura.Router can also be used as a micro-framework dispatcher!

  1. […] Aura.Router can also be used as a micro-framework dispatcher! Posted on November 8, 2012 by codegooroo Sometimes you may wish to use Aura as a micro-framework. It’s also possible to assigning anonymous function to controller: <?php $map->add(“read”, “/blog/read/{:id}{:format}”, [ "params" => [ "id" => "(d+)", "format" => "(..+)?", ], “values” => [ “controller” => function ($args) … Continue reading ? […]

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>