Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: executed other match group route #9340

Closed
kirankumarmitnas opened this issue Dec 27, 2024 · 3 comments
Closed

Bug: executed other match group route #9340

kirankumarmitnas opened this issue Dec 27, 2024 · 3 comments

Comments

@kirankumarmitnas
Copy link

kirankumarmitnas commented Dec 27, 2024

PHP Version

8.3

CodeIgniter4 Version

4.5.5

CodeIgniter4 Installation Method

Composer (using codeigniter4/appstarter)

Which operating systems have you tested for this bug?

Windows

Which server did you use?

apache

Database

No response

What happened?

Call other match ainto Routes

Steps to Reproduce

My Routes are write this kind

//app/config/Route.php

$routes->group('admin/(:any)',["filter" => "authGuard"], function ($routes) {

    $routes->group('course/inquiry', function ($routes) {
        $routes->group('reminder', function ($routes) {
            First Route =>   //$routes->get('list', 'Admin\CourseInquiry::reminderList'); 
              
        });
    });

    $routes->group('reminder', function ($routes) {
        Second Route =>$routes->get('list', 'Admin\Reminder::index');
    });
});

My Url is =>http://domain.com/index.php/admin/521d7941a1f28640069792fbb7dedd8e/course/inquiry/reminder/list

if We comment first one route of this route its execute second one Route .

Expected Output

it should be show route not found but its second one route are executed. that route are outside of that group and that route are different and outside side of group. If we want to execute first one route un comment that work perfectly.

Anything else?

No response

@kirankumarmitnas kirankumarmitnas added the bug Verified issues on the current code behavior or pull requests that will fix them label Dec 27, 2024
@michalsn
Copy link
Member

Not a bug. Please check what :any placeholder stands for: https://codeigniter.com/user_guide/incoming/routing.html#placeholders

@michalsn michalsn removed the bug Verified issues on the current code behavior or pull requests that will fix them label Dec 27, 2024
@kirankumarmitnas
Copy link
Author

let's you explain what happen whenever i am calling bellow url.
My url is "http://domain.com/index.php/admin/521d7941a1f28640069792fbb7dedd8e/course/inquiry/reminder/list"

here we are devided above url in 3 part

  1. "http://domain.com/index.php/"
  2. "admin/521d7941a1f28640069792fbb7dedd8e/"
  3. "/course/inquiry/reminder/list"

and my routes are there

First Group =>
$routes->group('admin/(:any)',function ($routes) {

Second Group=> 
   $routes->group('course/inquiry', function ($routes) {
           inside first Group=> 
	$routes->group('reminder', function ($routes) {
		$routes->get('list', 'Admin\CourseInquiry::reminderList');
	});
});

   Third Group=> 
$routes->group('reminder', function ($routes) {
	$routes->get('list', 'Admin\Reminder::index');
});

});

when we enter url on addressbar
first routes are enter because we added wild card(:any) so this path enter my first route of group like in this

$routes->group('admin/(:any)',function ($routes) {

});

then it should be execute 2 group of my route because i am defined route is "/course/inquiry/reminder/list"

$routes->group('course/inquiry', function ($routes) {
$routes->group('reminder', function ($routes) {
$routes->get('list', 'Admin\CourseInquiry::reminderList');
});
});

it's executed perfectly but whenever i am committed above route of group which is "$routes->get('list', 'Admin\CourseInquiry::reminderList'); " then it will executed third one routes.

$routes->group('reminder', function ($routes) {
$routes->get('list', 'Admin\Reminder::index');
});

@michalsn
Copy link
Member

Please use code blocks when you paste code samples, because it's hard to read.

In your initial report, you wrote:

if We comment first one route of this route its execute second one Route .... it should be show route not found but its second one route are executed.

The result is correct, because (:any) will match multiple segments, thereforce, the second route is correct match.
If you want it to work differently, you have to use (:segment) placeholder instead or structure your routes differently.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants