View URL Helpers

I am currently usiing Mezzio and having an issue using url helpers while trying to create canonical links for a blog page (hopefully can explain this properly):

I have the following code in the view:

$this->headLink([
‘rel’ => ‘canonical’,
‘href’ => $this->serverUrl($this->url(‘blog.list’))
], ‘PREPEND’);

The following route:

$app->get(
‘/blog/[category/{category:[a-zA-Z][a-zA-Z0-9_-]*}]’,
Blog\Handler\ListPageHandler::class,
‘blog.list’
);

The url works fine when visiting /blog/ and returns /blog/, however when visting /blog/category/videos the url returned in the helper is /blog/category/videos and should return /blog/

It’s as if the helpers are automatically populating the route params somehow? Is this a bug or intended functionality?

I think you are searching for the option reuse_result_params:

$this->serverUrl($this->url('blog.list', [], [], null, ['reuse_result_params' => false]))
1 Like

As soon as I saw that, was like “Doh!”.

Thanks pal, was exactly that!