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

Back references not working in route #1761

Closed
tcrawf opened this issue Feb 25, 2019 · 2 comments
Closed

Back references not working in route #1761

tcrawf opened this issue Feb 25, 2019 · 2 comments

Comments

@tcrawf
Copy link

tcrawf commented Feb 25, 2019


Back-references not working in route

Guidance from user manual
Note: If you use back-references you must use the dollar syntax rather than the double backslash syntax. A typical RegEx route might look something like this:
$routes->add('products/([a-z]+)/(\d+)', '$1::id_$2');

Code
Routes.php file:
$routes->get('products/([a-z]+)/(:num)','$1::view/$2');

Action
Go to http://site.test/products/trucks/5 on local development machine

Expected behaviour (based on user manual)
Load view() method on Trucks controller called with the numerical product id.

Actual behaviour
404 Error
Controller or its method is not found: \App\Controllers$1::view
The back-reference is not being converter from $1 to Trucks

CodeIgniter 4 version
v4.0.0-alpha.5

Affected module(s)
\Codeigniter\Router

Context

  • OS: Ubuntu 18.04
  • Web server [e.g. Apache 2.4.29]
  • PHP version [e.g. 7.2.10]
@lonnieezell
Copy link
Member

There isn't any variable variable substitution done for the controller name. So - it's not that it doesn't work, it just doesn't work for the controller. And that's by design. To allow any controller in the system to be ran based on user input like that is asking for a giant security hole.

@tcrawf
Copy link
Author

tcrawf commented Feb 26, 2019

Thanks for the clear feedback. I understand this was possible in the previous version. The user guide indicates this is possible and might benefit from a correction on this item:
https://codeigniter4.github.io/userguide/incoming/routing.html
$routes->add('products/([a-z]+)/(\d+)', '$1::id_$2');

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