Routing
extends BaseConfig
in package
Routing configuration
Table of Contents
Properties
- $autoRoute : bool
- 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.
- $defaultController : string
- For Auto Routing.
- $defaultMethod : string
- For Defined Routes and Auto Routing.
- $defaultNamespace : string
- For Defined Routes and Auto Routing.
- $moduleRoutes : array<string, string>
- For Auto Routing (Improved).
- $multipleSegmentsOneParam : bool
- For Defined Routes.
- $override : bool
- Whether to override properties by Env vars and Registrars.
- $override404 : string|null
- Sets the class/method that should be called if routing doesn't find a match. It can be the controller/method name like: Users::index
- $prioritize : bool
- For Defined Routes.
- $registrars : array<string|int, mixed>
- An optional array of classes that will act as Registrars for rapidly setting config class properties.
- $routeFiles : array<int, string>
- For Defined Routes.
- $translateURIDashes : bool
- For Auto Routing.
- $translateUriToCamelCase : bool
- For Auto Routing (Improved).
- $didDiscovery : bool
- Has module discovery happened yet?
- $moduleConfig : Modules|null
- The modules configuration.
Methods
- __construct() : mixed
- Will attempt to get environment variables with names that match the properties of the child class.
- __set_state() : mixed
- getEnvValue() : string|null
- Retrieve an environment-specific configuration setting
- initEnvValue() : void
- Initialization an environment-specific configuration setting
- registerProperties() : void
- Provides external libraries a simple way to register one or more options into a config file.
Properties
$autoRoute
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.
public
bool
$autoRoute
= false
If FALSE, will stop searching and do NO automatic routing.
$defaultController
For Auto Routing.
public
string
$defaultController
= 'Home'
The default controller to use when no other controller has been specified.
Default: 'Home'
$defaultMethod
For Defined Routes and Auto Routing.
public
string
$defaultMethod
= 'index'
The default method to call on the controller when no other method has been set in the route.
Default: 'index'
$defaultNamespace
For Defined Routes and Auto Routing.
public
string
$defaultNamespace
= 'App\Controllers'
The default namespace to use for Controllers when no other namespace has been specified.
Default: 'App\Controllers'
$moduleRoutes
For Auto Routing (Improved).
public
array<string, string>
$moduleRoutes
= []
Map of URI segments and namespaces.
The key is the first URI segment. The value is the controller namespace. E.g., [ 'blog' => 'Acme\Blog\Controllers', ]
$multipleSegmentsOneParam
For Defined Routes.
public
bool
$multipleSegmentsOneParam
= false
If TRUE, matched multiple URI segments will be passed as one parameter.
Default: false
$override
Whether to override properties by Env vars and Registrars.
public
static bool
$override
= true
$override404
Sets the class/method that should be called if routing doesn't find a match. It can be the controller/method name like: Users::index
public
string|null
$override404
= null
This setting is passed to the Router class and handled there.
If you want to use a closure, you will have to set it in the routes file by calling:
$routes->set404Override(function() { // Do something here });
Example: public $override404 = 'App\Errors::show404';
$prioritize
For Defined Routes.
public
bool
$prioritize
= false
If TRUE, will enable the use of the 'prioritize' option when defining routes.
Default: false
$registrars
An optional array of classes that will act as Registrars for rapidly setting config class properties.
public
static array<string|int, mixed>
$registrars
= []
$routeFiles
For Defined Routes.
public
array<int, string>
$routeFiles
= [APPPATH . 'Config/Routes.php']
An array of files that contain route definitions. Route files are read in order, with the first match found taking precedence.
Default: APPPATH . 'Config/Routes.php'
$translateURIDashes
For Auto Routing.
public
bool
$translateURIDashes
= false
Whether to translate dashes in URIs for controller/method to underscores. Primarily useful when using the auto-routing.
Default: false
$translateUriToCamelCase
For Auto Routing (Improved).
public
bool
$translateUriToCamelCase
= false
Whether to translate dashes in URIs for controller/method to CamelCase. E.g., blog-controller -> BlogController
If you enable this, $translateURIDashes is ignored.
Default: false
$didDiscovery
Has module discovery happened yet?
protected
static bool
$didDiscovery
= false
$moduleConfig
The modules configuration.
protected
static Modules|null
$moduleConfig
Methods
__construct()
Will attempt to get environment variables with names that match the properties of the child class.
public
__construct() : mixed
The "shortPrefix" is the lowercase-only config class name.
__set_state()
public
static __set_state(array<string|int, mixed> $array) : mixed
Parameters
- $array : array<string|int, mixed>
getEnvValue()
Retrieve an environment-specific configuration setting
protected
getEnvValue(string $property, string $prefix, string $shortPrefix) : string|null
Parameters
- $property : string
- $prefix : string
- $shortPrefix : string
Return values
string|nullinitEnvValue()
Initialization an environment-specific configuration setting
protected
initEnvValue(array<string|int, mixed>|bool|float|int|string|null &$property, string $name, string $prefix, string $shortPrefix) : void
Parameters
- $property : array<string|int, mixed>|bool|float|int|string|null
- $name : string
- $prefix : string
- $shortPrefix : string
registerProperties()
Provides external libraries a simple way to register one or more options into a config file.
protected
registerProperties() : void