Missing argument in route when using `url_to` or `route_to` with regex routes
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 48/100
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.
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:
$routes->get('/test(/(:any))?', 'Test::direct/$1', ['as' => 'test']);
Linking as below works:
<a href="/test">No parameter</a>
<a href="/test/param1">1 parameter</a>
<a href="/test/param1/param2">2 parameters</a>
But using both url_to or route_to fails:
<a href="<?= url_to('test') ?>">No parameter</a>
<a href="<?= url_to('test', 'param1') ?>">1 parameter</a>
<a href="<?= url_to('test', 'param1', 'param2') ?>">2 parameters</a>
Steps to Reproduce
- Add the new routes in
Routes.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']);
- Create the
Testcontroller:
<?php
namespace App\Controllers;
class Test extends BaseController
{
public function direct(...$params): string
{
return view('test', ['params' => $params]);
}
public function urlto(...$params): string
{
return view('test_urlto', ['params' => $params]);
}
public function routeto(...$params): string
{
return view('test_routeto', ['params' => $params]);
}
}
- Create the respective views:
A) direct view
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Test</title>
</head>
<body>
<h1>Testing CI4 Routing with Parameters</h1>
<h2>Test using string directly</h2>
<ul>
<li>
<a href="/test">No parameter</a>
</li>
<li>
<a href="/test/param1">1 parameter</a>
</li>
<li>
<a href="/test/param1/param2">2 parameters</a>
</li>
<li>
<a href="/test/param1/param2/param3">3 parameters</a>
</li>
</ul>
<h3>Passed Parameters</h3>
<ul>
<?php foreach ($params as $param) : ?>
<li><?= $param ?></li>
<?php endforeach; ?>
</body>
</html>
B) view using url_to
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Test</title>
</head>
<body>
<h1>Testing CI4 Routing with Parameters</h1>
<h2>Test using <code>url_to</code></h2>
<ul>
<li>
<a href="<?= url_to('urlto') ?>">No parameter</a>
</li>
<li>
<a href="<?= url_to('urlto', 'param1') ?>">1 parameter</a>
</li>
<li>
<a href="<?= url_to('urlto', 'param1', 'param2') ?>">2 parameters</a>
</li>
<li>
<a href="<?= url_to('urlto', 'param1', 'param2', 'param3') ?>">3 parameters</a>
</li>
</ul>
<h3>Passed Parameters</h3>
<ul>
<?php foreach ($params as $param) : ?>
<li><?= $param ?></li>
<?php endforeach; ?>
</body>
</html>
- 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;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.
- Ngôn ngữ chính
- PHP
- Star
- 6k
- Fork
- 2k
- Merge trung bình
- 1 ngày 22 giờ
- Pull request đã merge (30 ngày)
- 59
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của codeigniter4/CodeIgniter4
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
codeigniter4/CodeIgniter4#10616 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
codeigniter4/CodeIgniter4#10618 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 62/100
codeigniter4/CodeIgniter4#10617 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 25/100
codeigniter4/CodeIgniter4#10615 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 48/100
codeigniter4/CodeIgniter4#10589 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của codeigniter4/CodeIgniter4
Issue tương tự
-
sync-en
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
Maintainer thường phản hồi trong vòng 1 ngày
-
sync-en
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 4 ngày
-
Перевод устарел
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 85/100
-
bug
Độ khó 2/5 Nửa ngày Mức phù hợp với người mới 76/100
m3ue/m3u-editor#1604 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
femiwiki/docker-mediawiki#1497 ·
Maintainer thường phản hồi trong vòng 1 ngày