Auth是簡單的登陸組件,一般都是先建立user表,字段username,password,如果不是這樣就必須另行顯式說明。
<?php
class AppController extends Controller {
var $components = array('Auth','Session');
function beforeFilter() {
//Configure AuthComponent配置Auth組件,Auth組件採用SHA1的加密方法。
$this->Auth->allowedActions = array('display','logout','login');
$this->Auth->loginAction = array('controller' => 'users', 'action' => 'login');
$this->Auth->logoutRedirect = array('controller' => 'users', 'action' => 'login');
$this->Auth->loginRedirect = array('controller' => 'products', 'action' => 'index');
if(!$this->Session->check('lang'))
{
$this->Session->write('lang',0);
}
date_default_timezone_set('Asia/Chongqing');
}
}
現在app_controller進行基本的設置,還要建立user的model和controller,建立login和louout方法。它使用SHA1進行加密。可以更改成md5。
function beforeFilter() {
parent::beforeFilter();
$this->Auth->allow('*');
}
一般在每個controller使用這個來進行allow的方法設置,放行一些方法,免得被禁止權限。