我使用的是 CakePHP 2.2,这里是我使用的教程的链接:link
非常重要:我关闭了 Inflector
我不在乎 ACL(它有效:D),我的 AUTH 不起作用...$this->Auth->login()
返回 false...
用户控制器:
App::uses('AppController', 'Controller');
class UsersController extends AppController {
public $helpers = array('Html','Form');
public $components = array('Auth' => array('authenticate' => array('form' => array('fields' => array('username' => 'login')))),'Session');
function beforeFilter() {
//$this->Auth->allow('logout', 'view');
$this->Auth->allow('*');
parent::beforeFilter();
}
function login() {
if ($this->Auth->login())
{
$this->redirect($this->Auth->redirect());
} else
{
$this->Session->setFlash(__('Invalid username or password, try again'));
}
应用控制器:
App::uses('Alc', 'Controller', 'Controller');
class AppController extends Controller {
public $components = array('Auth'=>array('authorize' => array('Actions' => array('actionPath' => 'controllers'))), 'Session');
public $helpers = array('Html', 'Form', 'Session');
function beforeFilter() {
$this->Auth->userModel = 'Users';
$this->Auth->loginAction = array('controller' => 'users', 'action' => 'login');
$this->Auth->allow('index', 'view', 'admin', 'edit', 'login', 'logout', 'add');
$this->Auth->logoutRedirect = array('controller' => 'novosti', 'action' => 'index');
$this->Auth->loginRedirect = array('controller' => 'novosti', 'action' => 'index');
}
用户型号:
App::uses('AuthComponent', 'Controller/Component');
class Users extends AppModel {
public function beforeSave($options = array()) {
if (isset($this->data[$this->alias]['password'])) {
$this->data['Users']['password'] = AuthComponent::password($this->data['Users']['password']);
}
return true;
}
public function bindNode($user) {
return array('model' => 'Groups', 'foreign_key' => $user['Users']['groups_id']);
}
查看文件:
<?php
echo $this->Session->flash('auth');
echo $this->Form->create('Users', array('action' => 'login'));
echo $this->Form->inputs(array(
'legend' => __('Login', true),
'Login',
'password'
));
echo $this->Form->end('Login');
?>
没有可用的 SQL 转储
我去看看所有这些文件....并将所有文件lib/controller/components/Authcomponents.php
更改为; 还查看了设置变量和我发现的所有地方我将模型名称从更改为,并且登录字段也从更改为lib/controller/components/auth/*
Auth.User
Auth.Users
User
Users
username
Login