PHPackages                             monken/ci4-route-attributes - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. monken/ci4-route-attributes

ActiveLibrary[Framework](/categories/framework)

monken/ci4-route-attributes
===========================

Make CodeIgniter4 Router supports automatic binding of Controller Method with PHP8 Attribute syntax.

v1.0.0(4y ago)891MITPHPPHP ^8

Since Jan 9Pushed 4y ago1 watchersCompare

[ Source](https://github.com/monkenWu/CodeIgniter4-Route-Attributes)[ Packagist](https://packagist.org/packages/monken/ci4-route-attributes)[ RSS](/packages/monken-ci4-route-attributes/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)Dependencies (2)Versions (4)Used By (0)

CodeIgniter4-Route-Attribute
============================

[](#codeigniter4-route-attribute)

[![Latest Stable Version](https://camo.githubusercontent.com/ab8e637e908dce10c0c1fa5027cdba26999c12cc2da4fd4829a2854f54da3725/687474703a2f2f706f7365722e707567782e6f72672f6d6f6e6b656e2f6369342d726f7574652d617474726962757465732f76)](https://packagist.org/packages/monken/ci4-route-attributes) [![Total Downloads](https://camo.githubusercontent.com/c9150f39ef9e35c45c170f3a16b96bf1ca27a1b0dbf91685a70715ac21993c22/687474703a2f2f706f7365722e707567782e6f72672f6d6f6e6b656e2f6369342d726f7574652d617474726962757465732f646f776e6c6f616473)](https://packagist.org/packages/monken/ci4-route-attributes) [![Latest Unstable Version](https://camo.githubusercontent.com/f3831a02aa43a07f3806d38843b67f3fd4ecdfd2a31d28b601d74cbda5e6a05d/687474703a2f2f706f7365722e707567782e6f72672f6d6f6e6b656e2f6369342d726f7574652d617474726962757465732f762f756e737461626c65)](https://packagist.org/packages/monken/ci4-route-attributes) [![License](https://camo.githubusercontent.com/13bdbc5bf109d9d784abd7763508b31b2c74ff6218b70cb8087346d1c9c943fb/687474703a2f2f706f7365722e707567782e6f72672f6d6f6e6b656e2f6369342d726f7574652d617474726962757465732f6c6963656e7365)](https://packagist.org/packages/monken/ci4-route-attributes) [![PHP Version Require](https://camo.githubusercontent.com/b87a3cf43381376cbe109fa689f06bf20b9df5b992bca2bd16c7fbf6e788be0d/687474703a2f2f706f7365722e707567782e6f72672f6d6f6e6b656e2f6369342d726f7574652d617474726962757465732f726571756972652f706870)](https://packagist.org/packages/monken/ci4-route-attributes)

You can use this library to make CodeIgniter4 able to define routing settings of controllers through comments.

[中文手冊](README_zh-TW.md)

- [CodeIgniter4-Route-Attribute](#codeigniter4-route-attribute)
    - [Quick demo](#quick-demo)
    - [Installation Guide](#installation-guide)
        - [Requirements](#requirements)
        - [Composer Install](#composer-install)
    - [Instructions](#instructions)
        - [Production and Development Environment](#production-and-development-environment)
            - [Configuration File](#configuration-file)
            - [Generate Route Attribute Definition File](#generate-route-attribute-definition-file)
            - [Update Route Attribute Definition File](#update-route-attribute-definition-file)
        - [Route](#route)
            - [options](#options)
            - [ignoreGroup](#ignoregroup)
            - [Placeholder](#placeholder)
            - [Single Method to declare multiple Routes](#single-method-to-declare-multiple-routes)
        - [RouteRESTful](#routerestful)
            - [Resource Route](#resource-route)
            - [Presenter Route](#presenter-route)
            - [websafe](#websafe)
            - [only](#only)
            - [except](#except)
            - [placeholder](#placeholder)
            - [options](#options-1)
            - [ignoreGroup](#ignoregroup-1)
        - [RouteGroup](#routegroup)
        - [RouteEnvironment](#routeenvironment)

Quick demo
----------

[](#quick-demo)

```
namespace App\Controllers;

use monken\Ci4RouteAttributes\Route;

class Ci4Controller extends BaseController
{
    #[Route(path: 'attr/route', methods: ["get"])]
    public function hello()
    {
        return "PHP8Attributes";
    }
}
```

Use the definition of `#[Route(path: 'attr/route', methods: ["get"])]`, means the same settings were done in your routing configuration:

```
$routes->get('attr/route', 'App\Controllers\Ci4Controller::hello');
```

This library will smartly connect your controller and routing automatically, which means you can access to the `hello` method in `Ci4Controller` through the path of `/attr/route`.

Installation Guide
------------------

[](#installation-guide)

### Requirements

[](#requirements)

1. CodeIgniter Framework 4
2. Composer
3. PHP8↑

### Composer Install

[](#composer-install)

Use Composer to download the library needed dependency under the project root.

```
composer require monken/ci4-route-attributes

```

Use the library built-in command to initialize the needed files.

```
php spark route-attr:init

```

The upper command will make to changes on our project.

1. `app/Config` will have a `RouteAttributes.php` configuration file, you can adjust the library's execution setting through this file. And it looks like this: ```
