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: route bug #3731

Closed
SyedMuradAliShah opened this issue Oct 6, 2020 · 2 comments
Closed

Bug: route bug #3731

SyedMuradAliShah opened this issue Oct 6, 2020 · 2 comments
Labels
bug Verified issues on the current code behavior or pull requests that will fix them

Comments

@SyedMuradAliShah
Copy link

SyedMuradAliShah commented Oct 6, 2020

Describe the bug
There is a bug while defining as in the route. When I use
$routes->add('admins/suspend/(:num)', 'AdminsController::suspend/$1', ['as' => 'suspend_admin']);
It give me error exception,

Undefined offset: 0
SYSTEMPATH\Router\RouteCollection.php at line 1347

When I change ['as' => 'suspend_admin'] to ['as' => 'suspends_admin'] or to anything its working.

Please check this, why it don't accept suspend_admin?

Added errorHandler ( arguments )

Array
(
    [from] => dashboard/admins/suspend/([0-9]+)
    [params] => Array
        (
        )

    [matches] => Array
        (
            [0] => Array
                (
                    [0] => ([0-9]+)
                )

            [1] => Array
                (
                    [0] => [0-9]+
                )

        )

    [pattern] => ([0-9]+)
    [index] => 0
)

Error generating
The error is only generate when I use base_url(route_to('suspend_admin') ). It looks like the issue is because of the dynamic argument.

When I remove (:num) the issue becomes to fix.

CodeIgniter 4 version

  • 4.0.4

Affected module(s)
Route

Context

  • OS: Window 10
  • Apache 2.4.46
  • 7.4.10
@SyedMuradAliShah SyedMuradAliShah added the bug Verified issues on the current code behavior or pull requests that will fix them label Oct 6, 2020
@InsiteFX
Copy link
Contributor

InsiteFX commented Oct 7, 2020

route_to takes a controller/method you should not need the base_url() try it without the base_url.

@michalsn
Copy link
Member

michalsn commented Oct 9, 2020

Please read how to use route_to() function in the user guide.

Basically, if you define a parameter in your URL, then you have to apply it to the function. In your case, something like this should work: route_to('suspend_admin', 123).

@michalsn michalsn closed this as completed Oct 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Verified issues on the current code behavior or pull requests that will fix them
Projects
None yet
Development

No branches or pull requests

3 participants