Skip to content

Instantly share code, notes, and snippets.

@mojaie
Created May 19, 2012 07:18
Show Gist options
  • Save mojaie/2729847 to your computer and use it in GitHub Desktop.
Save mojaie/2729847 to your computer and use it in GitHub Desktop.
CakePHP:test002_1
<?php
class TestsController extends AppController {
public $layout = null;
public function beforeFilter(){
//openaccessには誰でもアクセスできる
$this->Auth->allowedActions = array('openaccess');
//親クラス(AppController)読み込み
parent::beforeFilter();
}
public function isAuthorized() {
if ($this->Auth->user('group') == 'admin') {
//admin権限を持つユーザは全てのページにアクセスできる
return true;
} elseif ($this->Auth->user('group') == 'user') {
if ($this->action == 'useronly') {
//user権限を持つユーザはuseronlyにアクセスできる
return true;
}
}
return false;
}
//誰でもアクセスできるページ
public function openaccess() {
}
//会員だけアクセスできるページ
public function useronly() {
}
//管理者だけアクセスできるページ
public function adminonly() {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment