CodeIgniter Forums
CodeIgniter4 Attribute Routes - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Addins (https://forum.codeigniter.com/forumdisplay.php?fid=34)
+--- Thread: CodeIgniter4 Attribute Routes (/showthread.php?tid=81038)

Pages: 1 2


CodeIgniter4 Attribute Routes - kenjis - 01-17-2022

Hi, all.

I started to develop a package that you can set routes in your Controllers with PHP8 Attributes.

PHP Code:
namespace App\Controllers;

use 
Kenjis\CI4\AttributeRoutes\Route;

class 
News extends BaseController
{
    #[Route('news', methods: ['get'])]
    public function index()
    {
        ...
    }


This package generates Routes File from the Attribute Routes in your Controllers.
So, there is no extra overhead at runtime.

See https://github.com/kenjis/ci4-attribute-routes


RE: CodeIgniter4 Attribute Routes - kenjis - 01-26-2022

I've just released v0.1.0.
https://github.com/kenjis/ci4-attribute-routes/releases


RE: CodeIgniter4 Attribute Routes - kenjis - 01-26-2022

@luckmoshy Here is " CodeIgniter4 Attribute Routes", and you problem has nothing to do with it.
Please delete your comment, and create a new topic at https://forum.codeigniter.com/forum-30.html


RE: CodeIgniter4 Attribute Routes - kenjis - 02-12-2022

v0.2.0 was released!
https://github.com/kenjis/ci4-attribute-routes/releases


RE: CodeIgniter4 Attribute Routes - vyatka - 06-14-2022

nice package.
Just tested on my localhost playground.
One question: Is it OK what it's generate routes rules two times in RoutesFromAttribute.php file?

PHP Code:
<?php
// This file is automatically generated by ci4-attribute-routes.
// Please do not modify this file.
$routes->get('/''\App\Controllers\Main::index');
$routes->get('about''\App\Controllers\Main::about');
$routes->get('news''\App\Controllers\Main::news');
$routes->get('/''\App\Controllers\Main::index');
$routes->get('about''\App\Controllers\Main::about');
$routes->get('news''\App\Controllers\Main::news'); 



RE: CodeIgniter4 Attribute Routes - kenjis - 06-14-2022

Do you mean the file is generated?


RE: CodeIgniter4 Attribute Routes - vyatka - 06-15-2022

Yeah generated after  
Code:
php spark route:update



RE: CodeIgniter4 Attribute Routes - MGatner - 06-16-2022

The routes are all duplicated. Can you share your controller code, maybe on a GitHub Gist or somewhere that can handle larger pastes?


RE: CodeIgniter4 Attribute Routes - vyatka - 06-16-2022

Created repo - https://github.com/proweb/ci4-with-attributes
Just clone, install dependencies with composer and run 
PHP Code:
php spark route:update 

and you will see duplicates

P.S Just tested with "fresh" codeigniter install and no problem. Don't get why. Very strange.


RE: CodeIgniter4 Attribute Routes - kenjis - 06-16-2022

Remove App namespace in composer.json autoload.psr-4.

Code:
--- a/composer.json
+++ b/composer.json
@@ -18,10 +18,6 @@
        "ext-fileinfo": "Improves mime type detection for files"
    },
    "autoload": {
-        "psr-4": {
-            "App\\": "app",
-            "Config\\": "app/Config"
-        },
        "exclude-from-classmap": [
            "**/Database/Migrations/**"
        ]