Download the PHP package kenjis/ci4-attribute-routes without Composer
On this page you can find all versions of the php package kenjis/ci4-attribute-routes. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download kenjis/ci4-attribute-routes
More information about kenjis/ci4-attribute-routes
Files in kenjis/ci4-attribute-routes
Package ci4-attribute-routes
Short Description CodeIgniter4 Attribute Routes module
License MIT
Homepage https://github.com/kenjis/ci4-attribute-routes
Informations about the package ci4-attribute-routes
CodeIgniter4 Attribute Routes
This package generates a Routes File from the Attribute Routes in your Controllers.
- You can set routes in your Controllers, and disable Auto Routing.
- It generates a Routes File, so, there is no extra overhead at runtime.
- The generated Routes File can be used on PHP 7.3 production servers.
Requirements
- CodeIgniter 4.3.1 or later
- Composer
- PHP 8.0 or later
Installation
Configuration
-
Add the following code to the bottom of your
app/Config/Routes.php
file: - Disable auto routing and enable route priority:
This is optional, but strongly recommended.
Quick Start
1. Add Attribute Routes to your Controllers
Add #[Route()]
attributes to your Controller methods.
2. Update Routes File
APPPATH/Config/RoutesFromAttribute.php
is generated.
Check your routes with the php spark routes
command.
Route Attributes
Route
RouteGroup
RouteResource
RoutePresenter
Trouble Shooting
No routes in the generated routes file
You must import the attribute classes in your controllers.
E.g.:
Can't be routed correctly, or 404 error occurs
Show your routes with the php spark routes
command, and check the order of the routes.
The first matched route is the one that is executed.
The placeholders like (.*)
or ([^/]+)
takes any characters or segment. So you have to move the routes like that to the bottom.
In one controller, you can move the methods having such routes to the bottom.
Or set the priority of the routes with options
:
Zero is the default priority, and the higher the number specified in the priority
option, the lower route priority in the processing queue.
For Development
Installation
composer install
Available Commands
composer test // Run unit test
composer tests // Test and quality checks
composer cs-fix // Fix the coding style
composer sa // Run static analysys tools
composer run-script --list // List all commands