nubox/laminas-router-attributes 问题修复 & 功能扩展

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

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

nubox/laminas-router-attributes

最新稳定版本:1.0.0

Composer 安装命令:

composer require nubox/laminas-router-attributes

包简介

Use Symfony Route Attributes for Laminas Controller

README 文档

README

This guide will walk you through on how to use Symfony Route Attributes in Laminas Action Controller in PHP 8.1.

Requirements

  • PHP 8.1 or higher

Installation

Install the required packages via composer.

composer require nubox/laminas-router-attributes

Activate Plugin in our Laminas Application

return [
    // Retrieve list of modules used in this application.
    'modules' => [
        ...,
        \Laminas\Router\Attributes\Module::class, // or 'Laminas\Router\Attributes'
    ],
    ...
];

Usage

You can start by creating a new action controller which we will annotate with Symfony's Route attributes instead of the laminas configuration.

<?php 

namespace Module\Controller; 

use Laminas\Mvc\Controller\AbstractActionController;
use Symfony\Component\Routing\Attribute\Route;

class MyController extends AbstractActionController 
{ 
    #[Route('/my-path', name: 'my_route_name')] 
    public function myAction() { 
        //Your action code goes here...
    }
}

In the example above, #[Route('/my-path', name: 'my_route_name')] defines the path for the action and names the route.

That's all! You have successfully configured Symfony Route Attributes in your Laminas Action Controller.

Supported behavior from Symfony routes

  • configuration via Attributes
    • path -> domain route for methods or classes
    • name -> set up a name for the route
    • condition -> for more complex conditions about your route (require symfony/expression-language)
    • methods -> restrict the route to an explicit method
    • requirments -> Parameters Validation via RegExp
    • inline-defaults -> Inline default-settings (in combination with conditions, also)
    • defaults -> add default settings

Troubleshooting

If you run into any issue while trying to use Symfony Route attributes in your Laminas Action Controller, please refer to the respective Symfony and Laminas documentation.

Should you encounter issues that are not documented, kindly log them in our issues tracker.

Happy Coding!

统计信息

  • 总下载量: 18
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 1
  • 推荐数: 1

GitHub 信息

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

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2023-12-25