【发布时间】:2013-07-16 04:41:59
【问题描述】:
我的 auth 组件运行良好,只是它复制了我的 CakePHP 所在的文件夹。例如,我的整个 CakePHP 安装在 localhost/rh/,但是当登录重定向时,它会将用户发送到 localhost/rh/rh/controller。有什么想法吗?
应用控制器:
class AppController extends Controller {
public $components = array(
'Session',
'Auth' => array(
'loginRedirect' => array('controller' => 'users', 'action' => 'index'),
'logoutRedirect' => array('controller' => 'users', 'action' => 'index'),
'authError' => "You are not authorized to access that page",
'authorize' => array('Controller')
)
);
public function isAuthorized($user) {
return true;
}
public function beforeFilter() {
$this->Auth->allow('index', 'view');
}
}
用户控制器:
class UsersController extends AppController {
//before filter to allow users to register
public function beforeFilter() {
parent::beforeFilter();
$this->Auth->allow('add'); // Letting users register themselves
}
//login action
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'));
}
}
}
//logout action
public function logout() {
$this->redirect($this->Auth->logout());
}
【问题讨论】:
-
你用的是什么版本的 Cake?
-
AD7six:cakephp 版本 2.3.7
标签: authentication cakephp cakephp-2.3