1

I have done up a pagination system and am using the LinkPager widget, however this is generating links with ?? at the start instead of ? as it should.

This appears to be because of my UrlManager rule:

'foo/<name:[0-9a-zA-Z\-]+>.<some_id:\d+>/?' => 'foo/index',

I need to include that ? on the end or it can't resolve the page with an ending slash.

Here is how I am calling LinkPager:

LinkPager::widget(['pagination' => $pagination, 'options' => ['class' => 'clearfix']]);

Where $pagination is obviously the Pagination instance.

Is there any way I can stop it including the double question marks?

4

1 回答 1

1

The problem is in this part of the url rule: /?. You can't specify trailing slash like that, regex is wrong and outside of the pattern. Also you can't make it optional.

If you want to have the trailing slash, change the rule declaration to extended version and specify slash as suffix like that:

[
    'pattern' => 'foo/<name:[0-9a-zA-Z\-]+>.<some_id:\d+>',
    'route' => 'foo/index',
    'suffix' => '/',
],

Read more about alternative format of specifying url rules in corresponding section of official documentation.

Also check this question.

于 2015-01-19T16:34:02.477 回答