YII 응용 프로그램의 모든 페이지에서 인증을 시행해야합니다. 이렇게하려면 내가 http://www.heirbaut.nl/2010/02/23/forcing-a-yii-application-to-authenticate/에서 가져온 다음 코드로 SiteController
클래스를 확장했습니다Yii 강제 인증이 홈페이지/정적 페이지에서만 작동하는 이유는 무엇입니까?
/**
* @return array action filters
*/
public function filters(){
return array(
'accessControl', // perform access control for CRUD operations
);
}
/**
* Specifies the access control rules.
* This method is used by the 'accessControl' filter.
* @return array access control rules
*/
public function accessRules(){
return array(
array('allow', // allow all users to perform 'login'
'actions'=>array('login'),
'users'=>array('*'),
),
array('allow', // allow authenticated user to perform any action
'users'=>array('@'),
),
array('deny', // deny all users
'users'=>array('*'),
),
);
}
이 단지가의 index.php
URL에 대한, 로그인 폼에 unauthenticaed 사용자에 대한 모든 요청을 리디렉션되어 있는지 않습니다. 그러나 index.php?r=person
그리고 결과적으로 응용 프로그램의 주 메뉴는이 제한을 무시하고 인증에 관계없이 표시됩니다.
마 당신은'PersonController'를 가지고 있습니까? – topher
예. 모든 단일 컨트롤러가 동일한 코드를 참조해야합니까? 당신이 말한다면 물론 상속받을 새로운 수업을 만들어야합니다. 하지만 그것은 많은 보일러 플레이트 코드처럼 보입니다. 이 문제를 Yii의 사슬보다 높게 수정할 수는 없나요? – aelgoa