Dynamic URLs for Applications
by Castwide on 3-24-2008 0 commentsThe Phrameworks Kernel lets administrators define their own URLs for applications. The News application, for example, defaults to yourdomain.com/news, but it can just as easily be yourdomain.com/blog or yourdomain.com/articles. The Quick Enable option in the Applications admin uses the default URL, but the Pages admin lets you set the URL to whatever you want.
Developers need to take this feature into account when writing templates. Links and forms should use the base URL defined in the admin rather than a hard-coded default. This is easy to do in most cases. Phrameworks passes the variable @{phrame_page_base}@ to every page, which is the base URL for the application that is currently running.
In the News application, instead of linking to news categories like so:
<a href="/news/categories">Categories</a>
...the link should use the variable for the base:
<a href="@{phrame_page_base}@/categories">Categories</a>
Sometimes, however, developers need to point to an application other than the one that is currently running. This most commonly happens with plugins. A news feed plugin, for example, might need to be displayed on a page that is not part of the News application. In order to map links correctly, the plugin will need to pass the application's base to the plugin template.
An application's base URL can be accessed from the phrameworks object like so:
$phrameworks->applications['AppName']->mappedBase
To pass the mappedBase to the template:
$pm->setVariable('news_page_base', $phrameworks->applications['News']->mappedBase);