사용자가 컨트롤러 동작 add
및 edit
을 실행할 권한이 있는지 확인하는 기능이 내 컨트롤러에 isAuthorized()
있다고 가정 해 봅니다. 이제 내가 컨트롤러 액션 my_custom_action
안에 있다고 가정 해 봅시다.cakephp 다른 컨트롤러 작업 내에서 승인 된 확인
$this->Auth->isAuthorized();
내가이 만든 app_controller (가지) 함수에서 당신에게
사용자가 컨트롤러 동작 add
및 edit
을 실행할 권한이 있는지 확인하는 기능이 내 컨트롤러에 isAuthorized()
있다고 가정 해 봅니다. 이제 내가 컨트롤러 액션 my_custom_action
안에 있다고 가정 해 봅시다.cakephp 다른 컨트롤러 작업 내에서 승인 된 확인
$this->Auth->isAuthorized();
내가이 만든 app_controller (가지) 함수에서 당신에게
감사 : 내 사용자가 뭔가를 사용하여 내 컨트롤러 액션 my_custom_action
내부 작업을 add
및 edit
을 실행할 수있는 권한이있는 경우처럼 어떻게 확인합니까 . 먼저 사용중인 컨트롤러를 확인한 다음 컨트롤러에 대한 작업을 확인합니다. 이 'Simple Model-Based Access Control'제빵 기사를 살펴볼 수도 있습니다.
function isAuthorized() {
switch($this->name) {
case 'Everyone': /* EveryoneController */
return true;
break;
case 'Banned': /* BannedController */
$this->Auth->authError = __('You do not have permission to ', true).$this->action.' '.strtolower($this->name);
return false;
break;
default:
switch($this->action) {
case 'index':
return true;
break;
case 'add':
case 'edit':
case 'delete':
if (/* permission check */) {
return true;
} else {
$this->Auth->authError = __('You do not have permission to ', true).$this->action.' '.strtolower($this->name);
return false;
}
break;
default:
return true;
break;
}
break;
}
}
이 검사는 현재 사용자 my_custom_action '을 요청은 관리하고, 그래서 만약 액세스를 허용하는 경우.
public function isAuthorized($user) {
if (in_array($this->action, array('my_custom_action'))) {
if ($this->Auth->user('is_admin'))
return true;
else
return false;
}
}
'isAuthorized' 메소드가 어떻게 구현되는지에 따라 다릅니다. 당신이 해결하려고하는 실제 문제는 무엇입니까? 어쩌면 ACL 또는 이와 유사한 "실제"권한 시스템과 같은 것이 당신이 찾고있는 것일 수 있습니다. – deceze