Options¶
as¶
| Summary: | Names a route. |
|---|---|
| Types: | string |
| Default: |
|
Gives a name to the route and create a path function, e.g. ['as' =>
'foo'] creates a method foo_path which when called returns the url to the
route. If the URL contains variables those must be passed as arguments.
as is sometimes autogenerated, for instance when creating CRUD-resources
with $resource.
except¶
| Summary: | Restrict automatic routes for CRUD-resources. |
|---|---|
| Types: | array |
| Default: | [] |
Similar to only but instead of setting the entire list excepts
removes routes from the default list.
only¶
| Summary: | Restrict automatic routes for CRUD-resources. |
|---|---|
| Types: | array |
| Default: | ['list', 'create', 'new', 'update', 'show', 'edit', 'destroy'] |
For CRUD-resources only restricts which routes to automatically
setup. Allowed values:
listcreatenewupdateshoweditdestroy
to¶
| Summary: | Set target controller and method. |
|---|---|
| Types: | string |
| Default: | None |
Controller and method name in the form Controller#method. When not ambiguous
parts can be left out, for instance for CRUD-resources the controller is known
so #foo will call the same controller. Likewise if using Foo# the method
name will be derived from the pattern.
Examples:
Foo#barcallsbaronFoo.Foo#(contextual) calls method derived from pattern onFoo.#bar(contextual) callsbaron the same controller as the current scope uses.#(contextual) calls method derived from pattern on the same controller as the current scope uses.
_format¶
| Summary: | Set variable format (regexp). |
|---|---|
| Types: | regexp |
| Default: | [A-Za-z0-9-_.] |
When patterns contains variables, $get('foo/:bar'), the default format is
to allow [A-Za-z0-9\-_\.]. This can be restricted to narrow down the allowed
characters further by setting ['bar_format' => '\d+'] where bar is
the variable name and the value is a regexp to match it.
Any character is allowed, including /.
The default format can be modified by setting the static variables
Router::$default_format (global default) or
Router::$variable_formats (per variable default):
class MyRouter extends \Sidvind\PHPRoutes\Router {
/* default for all variables */
public static $default_format = '\d+';
/* default for 'foo' variable */
public static $variable_formats = [
'foo' => '\d+',
];
}