codeigniter4 / codeigniter4/CodeIgniter4
Missing argument in route when using `url_to` or `route_to` with regex routes
- Ngôn ngữ chính
- PHP
- Star
- 6k
- Fork
- 2k
- Merge trung bình
- 1 ngày 11 giờ
- Pull request đã merge (30 ngày)
- 73
Mô tả
### 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` or `route_to` to refer to it:
```php
$routes->get('/test(/(:any))?', 'Test::direct/$1', ['as' => 'test']);
```
Linking as below works:
```html
No parameter
1 parameter
2 parameters
```
But using both `url_to` or `route_to` fails:
```php
No parameter
1 parameter
2 parameters
```
### Steps to Reproduce
1. Add the new routes in `Routes.php`:
```php
$routes->get('/test(/(:any))?', 'Test::direct/$1', ['as' => 'test']);
$routes->get('/test_urlto(/(:any))?', 'Test::urlto/$1', ['as' => 'urlto']);
$routes->get('/test_routeto(/(:any))?', 'Test::routeto/$1', ['as' => 'routeto']);
```
2. Create the `Test` controller:
```php
$params]);
}
public function urlto(...$params): string
{
return view('test_urlto', ['params' => $params]);
}
public function routeto(...$params): string
{
return view('test_routeto', ['params' => $params]);
}
}
```
3. Create the respective views:
A) direct view
```html
Test
Testing CI4 Routing with Parameters
Test using string directly
Passed Parameters
```
B) view using `url_to`
```html
Test
Testing CI4 Routing with Parameters
Test using url_to
Passed Parameters
```
4. Access those views at: /test and /test_urlto
### Expected Output
No `InvalidArgumentException`, `Missing argument for "(/(:any)" in route "test_urlto(/(:any))?"` while using both `url_to` and `route_to` .
### Anything else?
- One can try it with `public bool $multipleSegmentsOneParam = true;` or `public bool $multipleSegmentsOneParam = false;` in `Routing.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.
Hướng dẫn đóng góp
Hướng nghiên cứu
Tái hiện lỗi bằng các route trong Routes.php và so sánh url_to với route_to khi sử dụng cả hai thiết lập multipleSegmentsOneParam trong Routing.php. Bắt đầu bằng cách lần theo việc xử lý tham số route từ các route regex có tên; hoàn thành khi tất cả các liên kết được hiển thị đều được tạo mà không có InvalidArgumentException và vẫn giữ nguyên các tham số như mong đợi.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- php
- Lĩnh vực
- backend
- Loại issue
- Lỗi
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức phù hợp với người mới
- 48/100