我使用CakePHP 2.2,這裏是入門指南的鏈接,我用:linkCakePHP的2.x的斜面登錄使用官方教程
非常重要的:我關掉變形器
我不有關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');
?>
NO SQL轉儲AVAILABLE
我去lib/controller/components/Authcomponents.php
和lib/controller/components/auth/*
和廁所k儘管所有這些文件....並且將所有Auth.User
改爲Auth.Users
;也看了,雖然設置變量和無處不在,我發現我從User
變型號,以Users
,也爲登錄字段從username
改爲Login
你爲什麼「關閉」Inflector?它不是用於確定CakePHP內核中類名和文件名的核心庫嗎? –
因爲我想使用俄羅斯名稱的型號名稱等...當你把它關掉所有工作正常...我的意思是整個CakePHP的東西使用它,什麼時候掉頭OFFF它不這樣即使烤烤COMAND我的一切我的表...正確,真的一切工作正常 – mikrowelt