如何创建动态路由取决于使用CakePHP的用户身份验证?

如何创建动态路由取决于使用CakePHP的用户身份验证?,php,cakephp,Php,Cakephp,通常我的主页路由使用CakePHP,如下所示: Router::connect('/', array('controller' => 'users', 'action' => 'login')); function login (){ ... ... ... if($this->Auth->user()){ $this-> redirect(array('controller'=>'users', 'action'=>

通常我的主页路由使用CakePHP,如下所示:

Router::connect('/', array('controller' => 'users', 'action' => 'login'));
function login (){
    ... ... ...
    if($this->Auth->user()){
         $this-> redirect(array('controller'=>'users', 'action'=>'dashboard'));
    }
    ... ... ...
}
Router::connect('/', array('controller'=>'users', 'action'=>'dashboard'));
用户登录主页后,我将其重定向如下:

Router::connect('/', array('controller' => 'users', 'action' => 'login'));
function login (){
    ... ... ...
    if($this->Auth->user()){
         $this-> redirect(array('controller'=>'users', 'action'=>'dashboard'));
    }
    ... ... ...
}
Router::connect('/', array('controller'=>'users', 'action'=>'dashboard'));
然后浏览器将url显示为“/用户/仪表板”。但我想将URL显示为“/”,即当登录用户主页路由将如下所示:

Router::connect('/', array('controller' => 'users', 'action' => 'login'));
function login (){
    ... ... ...
    if($this->Auth->user()){
         $this-> redirect(array('controller'=>'users', 'action'=>'dashboard'));
    }
    ... ... ...
}
Router::connect('/', array('controller'=>'users', 'action'=>'dashboard'));

如果您有任何想法,请与他人分享。

保持路由器原样:

路由器::连接“/”,数组“控制器”=>“用户”,“操作”=>“登录”

现在,在登录方法中,您必须使用以下内容:

检查用户是否已登录。 如果未登录,则呈现登录页面。 如果已登录,则呈现仪表板页面。 在登录功能中执行任何功能

function login (){
  if($this->Auth->user('id')){
if (!empty($this->data)) {
  //Do the login as per the information provided by user.
  //After log in redirect to the below
  $this->redirect('/');
}
 //Do something.........
 $this->render('/users/login');
  }else{
   //Do something.........
   $this->render('/users/dashboard');
  }
}

也许我错了,但我想你可以把你的家和dashbord连接起来。如果用户未登录,auth组件会将其重定向到登录页面,无论如何,我从中找到了一个想法