Welcome Guest, Not a member yet? Register   Sign In
CodeIgniter4 Attribute Routes
#1

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
Reply
#2

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

@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
Reply
#4

v0.2.0 was released!
https://github.com/kenjis/ci4-attribute-routes/releases
Reply
#5
Thumbs Up 

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'); 
Reply
#6

Do you mean the file is generated?
Reply
#7

Yeah generated after  
Code:
php spark route:update
Reply
#8

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

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.
Reply
#10

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/**"
        ]
Reply




Theme © iAndrew 2016 - Forum software by © MyBB