-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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: Missing argument in route when using url_to
or route_to
with regex routes
#9250
Comments
url_to
or route_to
with regex routes
Using the You can use: In any case, this is not a bug. |
I've been trying to use regex in routes for a long time. It failed. $routes->get('/test/(:any)', 'Test::direct/$1', ['as' => 'test_ext']);
$routes->get('/test', 'Test::direct/$1', ['as' => 'test']); To work, you need to specify a string for :any and not an array |
I couldn't disagree more... Because I'm using regular expressions (note the ? char) with (:any). And it also fails for '(/(.+))?' as mentioned in this carefully written bug report. And, by running the examples, one can see that routing mechanism is working flawlessly with or without arguments. Problem arises when using url_to. For me this is, at least, a framework inconsistency or missing feature (if not a bug). 😥 |
Yeah! Unfortunately every time this subject comes up it is treated as a feature, read the docs etc.... So I kindly suggest to remove the partial regex support from routes (a great loss since routing works fine with regex, only additional framework related functions like We could also explicitly says in the docs not to use the special '?' char in routes because of missing support. As I carefully showed in this bug report examples, regex with '?' works with or without arguments. Problem is framework support from related helper functions. |
PHP Version
8.3
CodeIgniter4 Version
CodeIgniter 4.5.5
CodeIgniter4 Installation Method
Composer (using
codeigniter4/appstarter
)Which operating systems have you tested for this bug?
Debian 12
Which server did you use?
fpm-fcgi
Database
N/A
What happened?
The following route definition works fine as long as you don't use
url_to
orroute_to
to refer to it:Linking as below works:
But using both
url_to
orroute_to
fails:Steps to Reproduce
Routes.php
:Test
controller:A) direct view
B) view using
url_to
Expected Output
No
InvalidArgumentException
,Missing argument for "(/(:any)" in route "test_urlto(/(:any))?"
while using bothurl_to
androute_to
.Anything else?
One can try it with
public bool $multipleSegmentsOneParam = true;
orpublic bool $multipleSegmentsOneParam = false;
inRouting.php
. The error is the same in both situations (just the parameters are treated differently, as expected).One can also use a regex like
'(/(.+))?'
instead of(/(:any))?
. The error remains.The text was updated successfully, but these errors were encountered: