2014-09-11 4 views
0

현재 CodeIgniter 및 IonAuth 프로젝트에서 작업 중이며이 문제가 발생했습니다.CodeIgniter 및 IonAuth '사용자가 로그인 한 경우'

시나리오 : 로그인 할 때 로그인 페이지에 계속 액세스 할 수 있습니다. 사용자가 이미 로그인되어 있기 때문에 내가하고 싶은이 액세스를 제거하는 것입니다

이 내 인증 클래스 내 인덱스 방법된다.

function index(){ 

     if (!$this->ion_auth->logged_in()) 
     { 
      //redirect them to the login page 
      redirect('auth/login', 'refresh'); 
     } 
     elseif($this->ion_auth->logged_in()) 
     { 
      //redirect them to the index page if logged in 
      redirect('/', 'refresh'); 
     } 
     elseif (!$this->ion_auth->is_admin()) 
     { 
      //redirect them to the home page because they must be an administrator to view this 
      redirect($this->config->item('base_url'), 'refresh'); 
     } 
} 

어떤 아이디어가 좋지 않을까!

답변

2

인증 컨트롤러를 엽니 다. 로그인 방법으로 이동하십시오. 맨 위에 다음 줄을 추가합니다

if($this->ion_auth->logged_in()) 
{ 
    //redirect them to the index page if logged in 
    redirect('/', 'refresh'); 
} 

또한, Ion_auth와 함께 제공되는 인증 컨트롤러가 정말 예이고, 참고 자료로 사용되어야한다. 모든 관련 문서를 읽으십시오.

  • https://www.codeigniter.com/user_guide/general/welcome.html
  • 편집 : 리디렉션을위한 '새로 고침'을 사용하여 그 용도를 가지고 있지만이 상황에서 아마 필요가 없습니다 있습니다 마십시오. 여기에 정보는에있다 :

    +1

    응답 주셔서 감사합니다! 빨리 확인해 볼게! – yowza

    +1

    고마워, 너 정말 나를 많이 도와 줬어! Stay Awesome! – yowza

    관련 문제