2009-11-11 3 views
1

로그인 한 경우에만 액세스 할 수있는 기본 페이지에 링크가 있습니다. 그러나이 링크를 클릭하면 로그인 페이지에 사용자 정의 오류 메시지를 표시하려고합니다. 'Message.auth').cakePHP의 인증에서 referer 받기

가 나는 코드의이 비트를 넣어 것 (의사 코드)

if (referer == '/users/reserve'){ 
    Message.auth = 'Please log in to reserve tickets'; 
} 
else { 
    Message.auth = 'Please log in to access that page'; 
} 

을 원하는 즉?

답변

1

당신이 로그인 뷰에서 출력되는 인증 플래시 메시지가 제공이 작동합니다 :

// login action of users_controller.ctp 
if ($this->Session->check('Auth.redirect') 
&& $this->Session->read('Auth.redirect') == '/users/reserve') { 
    $this->Session->write('Message.auth', 'Please log in to reserve tickets'); 
} 
+0

보통 물건이 있기 때문에 내가 실제로 리디렉션에는 preg_match를 사용했다 예비 후에, 그러나 그것은 열쇠이었다. 감사. – helloandre

+0

또한 세션 -> 쓰기를 사용할 때/tmp/cache에 이상한 문제가 있습니다. 이렇게하려면'setflash ("", 'default', array(), 'auth')'를 사용하는 것이 더 쉽습니다. – helloandre

1

referer를 얻으려면 $ this-> referer()을 호출하여 참조 URL을 가져온 다음 해당 값을보기로 전달할 수 있습니다.

참조 : referer