$defaultNamespace
$defaultNamespace : string
The namespace to be added to any Controllers.
Defaults to the global namespaces ()
Class RouteCollection
$fileLocator : \CodeIgniter\Autoloader\FileLocator
Handle to the file locator to use.
$moduleConfig : \Config\Modules
Handle to the modules config.
__construct(\CodeIgniter\Autoloader\FileLocator $locator, \Config\Modules $moduleConfig)
Constructor
\CodeIgniter\Autoloader\FileLocator | $locator | |
\Config\Modules | $moduleConfig |
addPlaceholder(string|array $placeholder, string $pattern = null) : \CodeIgniter\Router\RouteCollectionInterface
Registers a new constraint with the system. Constraints are used by the routes as placeholders for regular expressions to make defining the routes more human-friendly.
You can pass an associative array as $placeholder, and have multiple placeholders added at once.
string|array | $placeholder | |
string | $pattern |
setDefaultNamespace( $value) : \CodeIgniter\Router\RouteCollectionInterface
Sets the default namespace to use for Controllers when no other namespace has been specified.
$value |
setDefaultController( $value) : \CodeIgniter\Router\RouteCollectionInterface
Sets the default controller to use when no other controller has been specified.
$value |
setDefaultMethod( $value) : \CodeIgniter\Router\RouteCollectionInterface
Sets the default method to call on the controller when no other method has been set in the route.
$value |
setTranslateURIDashes(boolean $value) : \CodeIgniter\Router\RouteCollectionInterface
Tells the system whether to convert dashes in URI strings into underscores. In some search engines, including Google, dashes create more meaning and make it easier for the search engine to find words and meaning in the URI for better SEO. But it doesn't work well with PHP method names.
...
boolean | $value |
setAutoRoute(boolean $value) : \CodeIgniter\Router\RouteCollectionInterface
If TRUE, the system will attempt to match the URI against Controllers by matching each segment against folders/files in APPPATH/Controllers, when a match wasn't found against defined routes.
If FALSE, will stop searching and do NO automatic routing.
boolean | $value |
set404Override(callable|null $callable = null) : \CodeIgniter\Router\RouteCollectionInterface
Sets the class/method that should be called if routing doesn't find a match. It can be either a closure or the controller/method name exactly like a route is defined: Users::index
This setting is passed to the Router class and handled there.
callable|null | $callable |
setDefaultConstraint(string $placeholder) : \CodeIgniter\Router\RouteCollectionInterface
Sets the default constraint to be used in the system. Typically for use with the 'resource' method.
string | $placeholder |
map(array $routes = array(), array $options = null) : \CodeIgniter\Router\RouteCollectionInterface
A shortcut method to add a number of routes at a single time.
It does not allow any options to be set on the route, or to define the method used.
array | $routes | |
array | $options |
add(string $from, array|string $to, array $options = null) : \CodeIgniter\Router\RouteCollectionInterface
Adds a single route to the collection.
Example: $routes->add('news', 'Posts::index');
string | $from | |
array|string | $to | |
array | $options |
addRedirect(string $from, string $to, integer $status = 302) : \CodeIgniter\Router\RouteCollection
Adds a temporary redirect from one route to another. Used for redirecting traffic from old, non-existing routes to the new moved routes.
string | $from | The pattern to match against |
string | $to | Either a route name or a URI to redirect to |
integer | $status | The HTTP status code that should be returned with this redirect |
group(string $name, $params) : void
Group a series of routes under a single URL segment. This is handy for grouping items into an admin area, like:
Example: // Creates route: admin/users $route->group('admin', function() { $route->resource('users'); });
string | $name | The name to group/prefix the routes with. |
$params |
resource(string $name, array $options = null) : \CodeIgniter\Router\RouteCollectionInterface
Creates a collections of HTTP-verb based routes for a controller.
Possible Options: 'controller' - Customize the name of the controller used in the 'to' route 'placeholder' - The regex used by the Router. Defaults to '(:any)' 'websafe' - - '1' if only GET and POST HTTP verbs are supported
Example:
$route->resource('photos');
// Generates the following routes:
HTTP Verb | Path | Action | Used for...
----------+-------------+---------------+-----------------
GET /photos index an array of photo objects
GET /photos/new new an empty photo object, with default properties
GET /photos/{id}/edit edit a specific photo object, editable properties
GET /photos/{id} show a specific photo object, all properties
POST /photos create a new photo object, to add to the resource
DELETE /photos/{id} delete deletes the specified photo object
PUT/PATCH /photos/{id} update replacement properties for existing photo
If 'websafe' option is present, the following paths are also available:
POST /photos/{id}/delete delete
POST /photos/{id} update
string | $name | The name of the resource/controller to route to. |
array | $options | An list of possible ways to customize the routing. |
presenter(string $name, array $options = null) : \CodeIgniter\Router\RouteCollectionInterface
Creates a collections of HTTP-verb based routes for a presenter controller.
Possible Options: 'controller' - Customize the name of the controller used in the 'to' route 'placeholder' - The regex used by the Router. Defaults to '(:any)'
Example:
$route->presenter('photos');
// Generates the following routes:
HTTP Verb | Path | Action | Used for...
----------+-------------+---------------+-----------------
GET /photos index showing all array of photo objects
GET /photos/show/{id} show showing a specific photo object, all properties
GET /photos/new new showing a form for an empty photo object, with default properties
POST /photos/create create processing the form for a new photo
GET /photos/edit/{id} edit show an editing form for a specific photo object, editable properties
POST /photos/update/{id} update process the editing form data
GET /photos/remove/{id} remove show a form to confirm deletion of a specific photo object
POST /photos/delete/{id} delete deleting the specified photo object
string | $name | The name of the controller to route to. |
array | $options | An list of possible ways to customize the routing. |
match(array $verbs = array(), string $from, string|array $to, array $options = null) : \CodeIgniter\Router\RouteCollectionInterface
Specifies a single route to match for multiple HTTP Verbs.
Example: $route->match( ['get', 'post'], 'users/(:num)', 'users/$1);
array | $verbs | |
string | $from | |
string|array | $to | |
array | $options |
get(string $from, string|array $to, array $options = null) : \CodeIgniter\Router\RouteCollectionInterface
Specifies a route that is only available to GET requests.
string | $from | |
string|array | $to | |
array | $options |
post(string $from, string|array $to, array $options = null) : \CodeIgniter\Router\RouteCollectionInterface
Specifies a route that is only available to POST requests.
string | $from | |
string|array | $to | |
array | $options |
put(string $from, string|array $to, array $options = null) : \CodeIgniter\Router\RouteCollectionInterface
Specifies a route that is only available to PUT requests.
string | $from | |
string|array | $to | |
array | $options |
delete(string $from, string|array $to, array $options = null) : \CodeIgniter\Router\RouteCollectionInterface
Specifies a route that is only available to DELETE requests.
string | $from | |
string|array | $to | |
array | $options |
head(string $from, string|array $to, array $options = null) : \CodeIgniter\Router\RouteCollectionInterface
Specifies a route that is only available to HEAD requests.
string | $from | |
string|array | $to | |
array | $options |
patch(string $from, string|array $to, array $options = null) : \CodeIgniter\Router\RouteCollectionInterface
Specifies a route that is only available to PATCH requests.
string | $from | |
string|array | $to | |
array | $options |
options(string $from, string|array $to, array $options = null) : \CodeIgniter\Router\RouteCollectionInterface
Specifies a route that is only available to OPTIONS requests.
string | $from | |
string|array | $to | |
array | $options |
cli(string $from, string|array $to, array $options = null) : \CodeIgniter\Router\RouteCollectionInterface
Specifies a route that is only available to command-line requests.
string | $from | |
string|array | $to | |
array | $options |
environment(string $env, \Closure $callback) : \CodeIgniter\Router\RouteCollectionInterface
Limits the routes to a specified ENVIRONMENT or they won't run.
string | $env | |
\Closure | $callback |
reverseRoute(string $search, array ...$params) : string|false
Attempts to look up a route based on it's destination.
If a route exists:
'path/(:any)/(:any)' => 'Controller::method/$1/$2'
This method allows you to know the Controller and method and get the route that leads to it.
// Equals 'path/$param1/$param2'
reverseRoute('Controller::method', $param1, $param2);
string | $search | |
array | $params variadic |
getFilterForRoute(string $search) : string
Returns the filter that should be applied for a single route, along with any parameters it might have. Parameters are found by splitting the parameter name on a colon to separate the filter name from the parameter list, and the splitting the result on commas. So:
'role:admin,manager'
has a filter of "role", with parameters of ['admin', 'manager'].
string | $search |
create(string $verb, string $from, string|array $to, array $options = null)
Does the heavy lifting of creating an actual route. You must specify the request method(s) that this route will work for. They can be separated by a pipe character "|" if there is more than one.
string | $verb | |
string | $from | |
string|array | $to | |
array | $options |