2016-11-30 29 views
0

我有與特定的方法的控制器登錄:CakePHP3驗證的redirectUrl路線破碎

public function login() { 

    if ($this->request->is('post')){ 
     $user = $this->Auth->identify(); 
     if ($user) { 
      $this->Auth->setUser($user); 
      return $this->redirect($this->Auth->redirectUrl()); 
     } 

    // not logged 
    $this->Flash->error('Your username or password is incorrect'); 

    } 
} 

和缺省路由看起來像

Router::scope('/', function (RouteBuilder $routes) { 
    $routes->fallbacks(DashedRoute::class); 
}); 

CakePHP中用戶登錄後引發錯誤

Error: A route matching "/" could not be found.

None of the currently connected routes match the provided parameters. Add a matching route to config/routes.php

當IMO它應該重定向到頁面(基於相關控制器)從哪裏登錄方法被執行。

登錄代碼基於that教程。

有什麼想法?

回答

1

要解決此問題:

請更新下面的行routes.php文件文件

路由器:: defaultRouteClass( 'DashedRoute');

路由器::範圍( '/',功能(RouteBuilder $路由){

$routes->connect('/', ['controller' => 'users', 'action' => 'index']); 

$routes->fallbacks('DashedRoute'); 

}); Plugin :: routes();

請在用戶控制器中創建index()。 讓我知道是否有問題。

+0

工程就像一個魅力。謝謝! – JackTheKnife