codeigniter4 / codeigniter4/CodeIgniter4

Missing argument in route when using `url_to` or `route_to` with regex routes

オープン
#9,250 コメント 5 件 リアクション 0 件 担当者 0 名 GitHub で見る
主要言語
PHP
スター
6k
フォーク
2k
平均マージ
1日 11時間
マージ済み PR(30日)
73

説明

### 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.

コントリビューションガイド

コントリビューションガイドを開く

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。