Путь перенаправления использует полный путь к контроллеру (перенаправление для bjyauthorize)

У меня проблемы с перенаправлением с помощью bjyauthorize. Я перешел по этой ссылке: Как перенаправить на страницу входа с помощью BjyAuthorize и может заставить работать перенаправление.

Проблема, с которой я сталкиваюсь, заключается в том, что редирект строит URL с полным путем к контроллеру.

http://lh/user/login?redirect=/talent/my/Myapp%5CController%5CProfile/index

where my route and controller are below:
route: talent/my
controller: Myapp\Controller\Profile

Код для создания строки перенаправления (edit: публикация полной функции onDispatchError):

public function onDispatchError(MvcEvent $e)
{
    // Do nothing if the result is a response object
    $result = $e->getResult();
    if ($result instanceof Response) {
        return;
    }

    $router = $e->getRouter();
    $match  = $e->getRouteMatch();

    // get url to the zfcuser/login route
    $options['name'] = 'zfcuser/login';
    $url = $router->assemble(array(), $options);

    // Work out where were we trying to get to
    $options['name'] = $match->getMatchedRouteName();

    $matchParams = $match->getParams();

    // [jh]
    // TODO: need to fix this in a smart way
    // have already posted the problem on stackru: https://stackru.com/questions/17461274/redirect-path-is-using-full-controller-path-redirect-for-bjyauthorize
    $newParams = array(
        'controller' => $matchParams["__CONTROLLER__"],
    );

    // [jh]
    // having an index in the url looks a bit unprofessional
    // so, here i'm removing it... code is a bit dirty
    if ( 'index' !=  $matchParams["action"] )
        $newParams['action'] = $matchParams["action"];


    $redirect = $router->assemble($newParams, $options);


    // set up response to redirect to login page
    $response = $e->getResponse();
    if (!$response) {
        $response = new HttpResponse();
        $e->setResponse($response);
    }
    $response->getHeaders()->addHeaderLine('Location', $url . '?redirect=' . $redirect);
    $response->setStatusCode(302);
}

Здесь я добавил var_dump для следующего $ match-> getParams ():

array(4) {
  ["__NAMESPACE__"]=>
  string(14) "Myapp\Controller"
  ["controller"]=>
  string(22) "Myapp\Controller\Profile"
  ["action"]=>
  string(5) "index"
  ["__CONTROLLER__"]=>
  string(7) "profile"
}

$ опции:

array(1) {
  ["name"]=>
  string(16) "route_my/default"
}

Я мог бы изменить параметры, чтобы в поле 'controller' было установлено значение 'profile', чтобы устранить эту проблему. Но я не думаю, что это лучший подход.

Пожалуйста посоветуй!

Спасибо,

Джастин

0 ответов

Другие вопросы по тегам