Pages are addressed as ?object=&action=&id=&page=. With
$PROJECT_CONF['tpl']['REWRITE_MODE'] on (this site) url() builds short paths like
/object/action/id/page and the router parses them back into the same $_GET; off, the same
calls give the query form, so code and templates never write either form by hand. The table renders each call both
ways (the setting is switched for the call only); the picker below runs fixed request paths through the parser of the
yf pattern on a copy of the rewrite class. Read-only. Classes: yf_rewrite, yf_rewrite_pattern_yf.
url() in PHP
url() returns absolute links; their common start https://yfix.net is shown as …
| Call | REWRITE_MODE on | off |
|---|---|---|
url('/docs') | …/docs | …/?object=docs |
url('/docs/install') | …/docs/install | …/?object=docs&action=install |
url(['object' => 'docs', 'action' => 'install']) | …/docs/install | …/?object=docs&action=install |
url(['object' => 'news', 'action' => 'show', 'id' => 42]) | …/news/42 | …/?object=news&action=show&id=42 |
url(['object' => 'shop', 'action' => 'products', 'id' => 7, 'page' => 3]) | …/shop/products/7/3 | …/?object=shop&action=products&id=7&page=3 |
url(['object' => 'shop', 'page' => 2]) | …/shop/0/2 | …/?object=shop&page=2 |
url('/shop/search', ['q' => 'shoes', 'sort' => 'price']) | …/shop/search?q=shoes&sort=price | …/?object=shop&action=search&q=shoes&sort=price |
url('/docs/install#requirements') | …/docs/install#requirements | …/?object=docs&action=install#requirements |
url(['task' => 'login']) | …/login | …/?task=login |
url('/@object/@action') | …/docs/demo | …/?object=docs&action=demo |
process_url('./?object=docs&action=install') | …/docs/install | …/?object=docs&action=install |
An action of show is left out, a page without an id gets id 0,
other keys become the query string, @object / @action name the current page,
process_url() rewrites a link written in the query form, admin links (url_admin()) always
keep the query form. In templates the same calls are {url(object=docs;action=install)}, see tpl/syntax.
From a path to $_GET
/ /docs /docs/install /docs/demo/tpl%2Fsyntax /news/42 /shop/products/7/3 /shop/0/2 /shop/search?q=shoes&sort=price /login /?object=docs&action=install
Request
/
$_GET after routing
| object | docs |
|---|---|
| action | show |
Back with url($_GET)
url(['object' => 'docs', 'action' => 'show'])| REWRITE_MODE on | …/docs |
|---|---|
| off | …/?object=docs&action=show |
Numbers after the object are an id (and a page), /login and
/logout set task, an empty path opens SITE_DEFAULT_PAGE, and with
yf_rewrite::$QUERY_ROUTE_ON_EMPTY_PATH (on here) /?object=docs&action=install routes like
/docs/install. The router keeps only a-z 0-9 _ - in object and action.