Build unprefixed URL from prefixed route

I am trying to create a URL to an unprefixed controller from a template that is used for a prefixed route. The following code causes an error “Missing Route”, even though ['controller' => 'Authors', 'action' => 'search'] is defined.

$this->Url->build([
    'prefix' => '',
    'controller' => 'Authors',
    'action' => 'search'
])

If I set prefix to null or remove it entirely, I get a prefixed URL (/admin/authors/search).

This is the context of the route/template i am calling it from:

[
    '_scheme' => 'http',
    '_host' => 'localhost',
    '_port' => (int) 3000,
    '_base' => '',
    'params' => [
        'pass' => [ ],
        'controller' => 'Articles',
        'action' => 'add',
        'prefix' => 'Admin',
        'plugin' => null,
        '_matchedRoute' => '/admin/articles/add',
        '_ext' => null,
    ],
]

I’m not sure, but I think you want 'prefix' => false.

1 Like

That does work (and kind of makes sense I guess), thank you!