2012-08-30 23 views
0

它是一种自定义的CakePHPauthError网址是什么?如果我期待到Auth组件我放在AppController我有一个重定向操作loginRedirectlogoutRedirect,但我不知道是不是可以设置类似authErrorRedirect如何在CakePHP中设置authError重定向动作?

<?php 
class AppController extends Controller { 

    public $components = array(
     'Session', 
     'Auth' => array(
      'loginRedirect' => array('controller' => 'users', 'action' => 'index'), 
      'logoutRedirect' => array('controller' => 'users', 'action' => 'index'), 
      'authError' => 'You don\'t have the right to go there.', 
      // something like this 
      'authErrorRedirect' => array('controller' => 'users', 'action' => 'login'), 
      'authorize' => array(
       'Controller', 
       'Actions' => array(
        'actionPath' => 'controllers' 
       ) 
      ), 
      'authenticate' => array(
       'Form' => array(
        'fields' => array('username' => 'email') 
       ) 
      ) 
     ), 
     'Acl' 
    ); 

我可以设置一个authError重定向行动?

回答

0

号如果按照简单的身份验证和授权应用实例@CakePHP Cookbook v2.x documentation你应该在登录操作,其中用于登录失败重定向“无效的用户名或密码......”。这些才有意义,如果你想为不同的操作重定向,在下面的例子中Login2身份

public function login() { 
    if ($this->request->is('post')) { 
     if ($this->Auth->login()) { 
      $this->redirect($this->Auth->redirect()); 
     } else { 
      $this->Session->setFlash(__('Invalid username or password, try again')); 
      $this->redirect(array('controller' => 'users', 'action' => 'login2')); 
     } 
    } 
} 
+0

我得到了它,如果用户进入一个资源不能够访问,他必须先登录,简单明了。 – vitto