您的位置:首页 > 编程语言 > PHP开发

cakephp菜鸟笔记-auth组件简单说明

2012-02-18 22:04 369 查看
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。

进行以上设置后,加入user记录后,就没有被Auth->allowedActions的就会被禁止。
function beforeFilter() {
parent::beforeFilter();
$this->Auth->allow('*');
}

一般在每个controller使用这个来进行allow的方法设置,放行一些方法,免得被禁止权限。

这只是简单的Auth组件使用,更详细的权限使用还需要使用ACL。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息