Skip to content

Dynamic URIs and Pages

Greg Bowler edited this page Sep 7, 2018 · 6 revisions

Having the router match all URIs to View and Logic resources is limiting when dynamic content is requested from a URI, such as a blog article at the URI /blog/2009/08/04/example-blog-title. It wouldn't be feasible to have a directory path for every single year, month and day!

A special syntax can be used to indicate to the router that a part of the requested URI is dynamic. The above URI can then link to the Page View file located at page/blog/@year/@month/@day/@title.html. The @title.html file will be served for any request under the blog directory that matches the URI pattern of /blog/year/month/day/title.

The Page View can be made dynamic by a adding Page Logic file at page/blog/@year/@month/@day/@title.php, which can be used to bind the correct data to the document and handle 404 errors for non-matching content.

Each part of the dynamic URI that is prefixed with an @ symbol can be retrieved by the dynamicPath property of the PageLogic class. For example, in the URI /blog/2009/08/04/example-blog-title, $this->dynamicPath->get("year") would return 2009, and $this->dynamicPath->get("title") would return "example-blog-title".

Clone this wiki locally