Router
Zemit will use the Phalcon MVC Router or the CLI Router.
Phalcon will pass every defined router parameters to the dispatcher's handler's action method. However, we found this behavior quite unstable when mixing parameters with integer and string keys because the parameters order will be mixed making the method parameters unusable in different situations and with different scenarios.
If you are using the Zemit\Dispatcher\AbstractDispatcher
, which is the default one used by default in Zemit,only the parameters with integer keys will be passed to the action method parameters.
Default Routes
Zemit will automatically add new routes. If the bootstrap mode is set to Console, the Zemit\Cli\Router
will be used, otherwise the Zemit\Bootstrap\Router
will be used by default.
Default MVC Routes
Localization MVC Routes
The default MVC Routes will allow loop through the allowed locale to define their respective default routes as well.
Note: the :locale
placeholder is not a valid placeholder. Refer yourself to the official Phalcon Router Documentation for the list of valid placeholders to use.
Zemit let you define the allowed locale, only the locale "en" is set into the zemit configuration by default. Zemit will define the specific routes for each allowed locale defined within the config.
If you add new locale to the LOCALE_ALLOWED
configuration, zemit will add their respective default routes as well. As an example, this configuration below:
Will generate the new default routes routes for these names below:
Creating your own Routers
MVC Router
CLI Router
Method #1: Defining your own Router from the Bootstrap
You can define your own router directly within the Bootstrap class by initializing the $router variable.
Perhaps you may want to use the initializer in this particular case so you can use the correct Router depending on the application type. The console (CLI) Application requires a different type of Router in order to work. This example below will allow your bootstrap to work while using the MVC or the CLI Phalcon Application.
Method #2: Loading using a custom Service Provider
This is a little bit more advanced. You could in fact avoid touching the bootstrap at all by setting your custom router service provider directly from the config.
Directly from the .env file as shown below:
Or from your own \App\Bootstrap\Config
custom class. The point is to replace the default Zemit Router Service Provider with your own:
Below is an example of what your custom router service provider should look like:
Last updated