riesenia/cakephp-routing
最新稳定版本:v1.3.0
Composer 安装命令:
composer require riesenia/cakephp-routing
包简介
CakePHP plugin for routing by attributes
README 文档
README
The riesenia/cakephp-routing package allows you to define routes using class attributes in your controllers. These routes are then compiled into a routes_compiled.php file, which is included in your application's routes.php file.
Configuration
if you want to add routes for controllers not in the default app namespace APP, pass namespace option to the command
routes:build -n Plugin
Defining routes
- Define your class routes using the
Resourcesattribute.
<?php namespace App\Controller; use Riesenia\Routing\Attribute\Resources; #[Resources(only: ['index', 'view'])] class AuthorsController extends AppController { }
- Define your method routes using the
Connectattribute.
When defining routes using the Connect attribute in PHP, adding / to the URI will stop prefixing your route with the controller name.
<?php namespace App\Controller; use Riesenia\Routing\Attribute\Connect; class AuthorsController extends AppController { #[Connect(uri: 'cool-author')] public function index() { // Controller logic for /authors/cool-author } #[Connect(uri: '/custom-author')] public function custom() { // Controller logic for /custom-author } }
Resulting Routes:
$builder->connect('/authors/cool-author', 'Authors::index',[]); $builder->connect('/custom-author', 'Authors::custom',[]);
Compiling Routes
Run the Routes Command:
This will compile your routes into a routes_compiled.php file.
Using Compiled Routes
Update your routes.php to include the compiled routes.
<?php use Cake\Routing\RouteBuilder; return static function (RouteBuilder $routes) { require CONFIG . 'routes_compiled.php'; };
统计信息
- 总下载量: 2.29k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-07-15