Options

as

Summary:

Names a route.

Types:

string

Default:
  • Unnamed for basic routes.
  • Autogenerated for CRUD-resources.

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:

  • list
  • create
  • new
  • update
  • show
  • edit
  • destroy

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#bar calls bar on Foo.
  • Foo# (contextual) calls method derived from pattern on Foo.
  • #bar (contextual) calls bar on 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 in routes.php by setting one of the following variables:

  • Router::$default_format (string) for a global default.
  • Router::$variable_formats (array) for per-variable format.
/* default for all variables */
static::$default_format = '\d+';

/* default for 'foo' variable */
static::$variable_formats = [
    'foo' => '\d+',
];