8000 Routing. Ability to set `_host` for the whole scope and have all routes inherit it? · Issue #18073 · cakephp/cakephp · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Routing. Ability to set _host for the whole scope and have all routes inherit it? #18073
Open
@mehov

Description

@mehov

Hi everyone

What I did

$routes->scope('/{org}', ['plugin' => $this->getName(), '_host' => 'example.com'], function ($routes) {
    $routes->connect('/', ['controller' => 'Orgs', 'action' => 'show'], ['pass' => ['org']]);
    $routes->connect('/contact', ['controller' => 'Orgs', 'action' => 'contact'], ['pass' => ['org']]);
    // ... other routes
});

What I expected to happen

All routes in this scope are connected only to example.com

What actually happened

All routes in this scope are available under the main application domain too

Workaround

$routes->scope('/{org}', ['plugin' => $this->getName()], function ($routes) {
    $routes->connect('/', ['controller' => 'Orgs', 'action' => 'show'], ['pass' => ['org'], '_host' => 'example.com']);
    $routes->connect('/contact', ['controller' => 'Orgs', 'action' => 'contact'], ['pass' => ['org'], '_host' => 'example.com']);
    // ... other routes
});

This gets the job done but is not DRY

Related

CakePHP Version

5.1.2

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0