Controllers
Create a class that inherits StandardPage to create a controller. Inside the controller, you have access to request paramaters, menus and context. Using a controller is a good options when selecting the render view (i.e. *.inc) dynamic at request time.
<?php
use UUP\Site\Page\Web\StandardPage;
//
// Use happy-new-year as request URI for this controller.
//
class HappyNewYearPage extends StandardPage
{
public function __construct()
{
parent::__construct("Happy new year!"); // Set page title
}
public function printContent()
{
printf("Happy new year %d, %s", date('Y'), $this->session->user);
}
}
Mapping target script
When looking for a matching controller, the character immediate following a '-' in the request URI gets converted to upper case. Finally, the Page suffix is appended. Examples of request URI to class names:
URI | Class | File |
---|---|---|
happy-new-year | HappyNewYearPage | happy-new-year.php |
index | IndexPage | index.php |
about | AboutPage | about.php |
Name conflicts:
Using the same name for directory and script in the same location will cause a conflict when dispatching a route. Just avoid it is the simple solution.
Secure content
It's possible to protect content by creating a secure page. The same can be done by calling $this->authorize() in a standard page controller.
The markup can be hidden automatic from unauthenticated users (guest) by adding the custom attribute auth="true" on any element. Hiding content won't protect anyone from viewing it and need to be accompanied by validation in request handler (called from this page).