Missing argument in route when using `url_to` or `route_to` with regex routes
維護者通常 1 天內回覆
還沒有人認領這個 Issue。
評估
研究方向
使用 Routes.php 中的路由重現失敗,並在 Routing.php 的 multipleSegmentsOneParam 兩種設定下比較 url_to 和 route_to。首先從具名正則表達式路由開始追蹤路由參數的處理;完成的標準是所有顯示的連結都能產生,不出現 InvalidArgumentException,並保留預期的參數。
由索引模型根據 Issue 內容生成。
描述
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.
- 主要語言
- PHP
- 星號
- 6k
- 分支
- 2k
- 平均合併
- 1 天 22 小時
- 30 天內合併 PR
- 59
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
codeigniter4/CodeIgniter4 的其他 Issue
-
難度 2/5 1-3 小時 新手友好度 72/100
codeigniter4/CodeIgniter4#10616 · 1 則留言 ·
維護者通常 1 天內回覆
-
難度 4/5 3-5 天 新手友好度 35/100
codeigniter4/CodeIgniter4#10618 ·
維護者通常 1 天內回覆
-
難度 3/5 1-2 天 新手友好度 62/100
codeigniter4/CodeIgniter4#10617 · 1 則留言 ·
維護者通常 1 天內回覆
-
難度 4/5 3-5 天 新手友好度 25/100
codeigniter4/CodeIgniter4#10615 · 1 則留言 ·
維護者通常 1 天內回覆
-
bug
難度 4/5 3-5 天 新手友好度 48/100
codeigniter4/CodeIgniter4#10589 · 3 則留言 ·
維護者通常 1 天內回覆
查看 codeigniter4/CodeIgniter4 的全部 Issue
相似的 Issue
-
needs-triage Platform(Default)
難度 2/5 1-3 小時 新手友好度 76/100
維護者通常 1 天內回覆
-
[Store] RstLoader detects headings inside indented code blocks可能已有人在做 @lazerg 今天認領。 未關閉Bug Status: Needs Review Store
難度 2/5 1-3 小時 新手友好度 82/100
維護者通常 1 天內回覆
-
bug repo:ckeditor
難度 2/5 1-3 小時 新手友好度 78/100
-
No Code Attached Yet
難度 2/5 1-3 小時 新手友好度 72/100
joomla/joomla-cms#48611 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 65/100
維護者通常 1 天內回覆