Skip to content

RouteBuilder->redirect doesn't allow custom routeClass #10144

@patrickconroy

Description

@patrickconroy

This is a (multiple allowed):

  • bug

  • enhancement

  • feature-discussion (RFC)

  • CakePHP Version: 3.3.13

  • Platform and Target: PHP 5.6.25, MySQL 5.6, Mac 10.12.2

What you did

$routes->redirect('/whatever', ['redirect' => 'whatever'], ['routeClass' => 'CustomRedirectRoute']);

What happened

The RouteBuilder is defined as

public function redirect($route, $url, array $options = [])
{
    $options['routeClass'] = 'Cake\Routing\Route\RedirectRoute';
    if (is_string($url)) {
        $url = ['redirect' => $url];
    }
    $this->connect($route, $url, $options);
}

What you expected to happen

Would it make sense to have it be this, to match what's in the static Router::redirect

public function redirect($route, $url, array $options = [])
{
    if (is_string($url)) {
        $url = ['redirect' => $url];
    }
    if (!isset($options['routeClass'])) {
        $options['routeClass'] = 'Cake\Routing\Route\RedirectRoute';
    }
    $this->connect($route, $url, $options);
}

Also, just a quick note about why I need a custom redirect class. If I have a URL like /controller/:stuff I want to be able to redirect that to https://anothercomain.com/something/:stuff (where stuff in the redirected URL is the stuff that was matched with :stuff (also I just found out there's a stuffed flatbread emoji).
I feel like that should be something in the core, but I'd be fine doing it in the custom class - although right now I can't use one.

Thanks

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions