Welcome Guest, Not a member yet? Register   Sign In
CodeIgniter4 Route Attribute

Hello everyone.

I designed a Library, which make CodeIgniter4 able to define routing settings of controllers through comments.

This library is a CodeIgniter4 Router presentative way under the PHP8 Attributes feature, it merely provides litte mapping and encapsulation for some CodeIgniter4 Router methods. 

By means of scanning the comments automatically inside the Controller, routes and methods will be connected, enables you to write routing rules straightforwardly, and maintain the relationship between Controllers and Routes in a convenient way.

Quick demo

PHP Code:
namespace App\Controllers;


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:

PHP Code:

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.

If you are interested in this library, feel free to visit our Github repository to know how to install and use.

Thank you.

Messages In This Thread
CodeIgniter4 Route Attribute - by monkenWu - 02-12-2022, 09:58 PM
RE: CodeIgniter4 Route Attribute - by InsiteFX - 02-13-2022, 01:56 AM
RE: CodeIgniter4 Route Attribute - by luckmoshy - 02-13-2022, 05:42 AM

Theme © iAndrew 2016 - Forum software by © MyBB