PHP Class Controller_PatternRouter, atk4
in Frontend:
$r = $this->add("Controller_PatternRouter")
->addRule("(news\/.*)", "news_item", array("u"))
->route();
if REQUEST_URI is "/news/some-name-of-your-news/", then router would:
1) set $this->app->page to "news_item"
2) set $_GET["u"] to "news/some-name-of-your-news/"
uri.
Authors:
[email protected],
[email protected].
Show file
Open project: atk4/atk4
Class Usage Examples
Public Properties
Property |
Type |
Description |
|
$app |
App_Web |
|
|
Protected Properties
Public Methods
Method |
Description |
|
addRule ( $regex, $target = null, $params = null ) |
Add new rule to the pattern router. If $regexp is matched, then
page is changed to $target and arguments returned by preg_match
are stored inside GET as per supplied params array. |
|
buildURL ( $junk, $url ) |
|
|
init ( ) |
}}} |
|
link ( $page, $args = [] ) |
Link method creates a bi-directional link between a URL and
a page along with some GET parameters. This method is
entirely tranpsarent and can be added for pages which
are already developed at any time. |
|
route ( ) |
Perform the necessary changes in the APP's page. After this
you can still get the orginal page in app->page_orig. |
|
setModel ( $model ) |
Allows use of models. Define a model with fields:
- rule
- target
- params (comma separated). |
|
url ( ) |
|
|
Method Details
Add new rule to the pattern router. If $regexp is matched, then
page is changed to $target and arguments returned by preg_match
are stored inside GET as per supplied params array.
public addRule ( $regex, $target = null, $params = null ) |
Example:
$this->link('profile',array('user_id'));
public link ( $page, $args = [] ) |
Perform the necessary changes in the APP's page. After this
you can still get the orginal page in app->page_orig.
and content of that model will be used to auto-fill routing
Property Details
public App_Web $app |
return |
App_Web |
|
$links protected property
protected array $links |
return |
array |
|
$rules protected property
protected array $rules |
return |
array |
|