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

Unable to use _remap without default method in controller #1928

Closed
krishnan57474 opened this issue Apr 9, 2019 · 1 comment
Closed

Unable to use _remap without default method in controller #1928

krishnan57474 opened this issue Apr 9, 2019 · 1 comment

Comments

@krishnan57474
Copy link

krishnan57474 commented Apr 9, 2019

Describe the bug
A controller with method other than _remap
creates error in routes toolbar collector.

CodeIgniter 4 version
CodeIgniter4 Beta 0.0.2

Affected module(s)
system\Debug\Toolbar\Collectors\Routes.php

Expected behavior, and steps to reproduce if appropriate

  1. Set CodeIgniter environment to development
  2. Rename index method to _remap in app/Controllers/Home.php
  3. run

You get method not exists error.

The following statement in system\Debug\Toolbar\Collectors\Routes.php:

    $method    = is_callable($router->controllerName()) ? new \ReflectionFunction($router->controllerName()) : new \ReflectionMethod($router->controllerName(), $router->methodName());

Calling \ReflectionMethod($router->controllerName(), $router->methodName()) without method_exists check
causes method not exists error.

Fix

    $method    = is_callable($router->controllerName()) ? new \ReflectionFunction($router->controllerName()) : new \ReflectionMethod($router->controllerName(), method_exists($router->controllerName(), '_remap') ? '_remap' : $router->methodName());
@jim-parry jim-parry added this to the 4.0.0-rc.2 milestone Sep 8, 2019
@jim-parry
Copy link
Contributor

Unable to reproduce this specific problem.
Applying the proposed solution breaks ControllerTesterTest, which expects an index() method.
The user guide says that index() is the default method, hence it seems reasonable that not having it, whether or not you have a _remap(), would cause problems.

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

2 participants