riesenia/cakephp-routing 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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

  1. Define your class routes using the Resources attribute.
<?php
namespace App\Controller;
use Riesenia\Routing\Attribute\Resources;

#[Resources(only: ['index', 'view'])]
class AuthorsController extends AppController
{
}
  1. Define your method routes using the Connect attribute.

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

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-07-15