{
    "href": "/post/2013/11/18/a-peek-at-aura-v2-aura-router/",
    "relId": "2013/11/18/a-peek-at-aura-v2-aura-router",
    "title": "A Peek At Aura v2 -- Aura.Router",
    "author": "pmjones",
    "markup": "html",
    "tags": [
        {
            "href": "/tag/aura/",
            "relId": "aura",
            "title": "Aura",
            "author": null,
            "created": "2020-09-14 21:51:57 UTC",
            "updated": [
                "2020-09-14 21:51:57 UTC"
            ],
            "markup": "markdown"
        },
        {
            "href": "/tag/php/",
            "relId": "php",
            "title": "PHP",
            "author": null,
            "created": null,
            "updated": [],
            "markup": "markdown"
        },
        {
            "href": "/tag/programming/",
            "relId": "programming",
            "title": "Programming",
            "author": null,
            "created": null,
            "updated": [],
            "markup": "markdown"
        }
    ],
    "created": "2013-11-18 17:46:30 UTC",
    "updated": [
        "2013-11-18 17:46:30 UTC"
    ],
    "html": "<blockquote>\n<p>Most routing systems combine the \u00e2\u0080\u009crouting\u00e2\u0080\u009d task with the \u00e2\u0080\u009cdispatch\u00e2\u0080\u009d task. That is, they both extract the parameters and pick the controller/action. Aura.Router v2, because of its truly independent nature, only does routing. It turns out that dispatching is something that can be independent of routing, and so we have a separate Aura.Dispatcher package to handle that (although you can use any dispatching system you like).</p>\n<p>\u2026</p>\n<p>Aura.Router v2 allows you to examine the $_SERVER values and pick a route based on them using the addServer() method. For example, if you want to match routes based on the HTTP_ACCEPT value \u00e2\u0080\u00a6</p>\n<pre id=\"scroll_to_here\"><code>&lt;?php\n$router-&gt;addRoute('json_only', '/accept/json/{id}')\n-&gt;addServer(array(\n  // must be of quality *, 1.0, or 0.1-0.9\n  'HTTP_ACCEPT' =&gt; 'application/json(;q=(*|1.0|[0.[1-9]]))?'\n));\n?&gt;\n</code></pre>\n<p>\u2026</p>\n<p>Sometimes we need a params in the route path to be sequentially optional. The classic example is a blog archive organized by year, month, and day. We don\u00e2\u0080\u0099t want to have to write three routes, one for /{year}, /{year}/{month}, and /{year}/{month}/{day}, each with repeated information about the route.</p>\n<p>In Aura.Router v2, there is a special notation similar to URI Templates that indicates sequentially optional params: <code>{/param1,param2,param3}</code></p>\n<p>\u2026</p>\n<p>We can now add REST resource routes in a single call to attachResource():</p>\n<pre><code>&lt;?php\n$router-&gt;attachResource('blog', '/blog');\n?&gt;\n</code></pre>\n<p>This will add seven REST routes with appropriate names, paths, HTTP methods, and token regexes \u2026</p>\n<p>If you decide those routes are not to your liking, you can override the default behavior by using setResourceCallable() to pass callable of your own to create resource routes.</p>\n</blockquote>\n<p>Via <a href=\"http://auraphp.com/blog/2013/11/18/aura-v2-router/\">A Peek At Aura v2 -- Aura.Router</a>.</p>\n"
}
