2011-11-25 4 views
0

인증 스크립트 작성 시간을 절약하기 위해 탱크 인증을 설치했습니다.Codeigniter HMVC에서 모듈 기능을 호출하는 방법은 무엇입니까? 탱크 인증

HMVC를 사용함에 따라 탱크 인증에는 자체 모듈 (modules/auth)이 있습니다.

로그인 스크립트를 사용하여 다른 모듈 (/ admin,/members 등)을 어떻게 보호 할 수 있습니까 ?? 내가 뭔가를 할 필요가 읽은 내용에서

:

modules::run('auth/is_logged_in'); 

내 인증 컨트롤러가 보이는 같은 :

<?php if (!defined('BASEPATH')) exit('No direct script access allowed'); 

class Auth extends MX_Controller 
{ 
    function __construct() 
    { 
     parent::__construct(); 

     $this->load->helper(array('form', 'url')); 
     $this->load->library('form_validation'); 
     //$this->load->library('security'); 
     $this->load->library('tank_auth'); 
     $this->lang->load('tank_auth'); 

    } 

    function index() 
    { 
     if ($message = $this->session->flashdata('message')) { 
      //$this->load->view('auth/auth/general_message', array('message' => $message)); 

      $main_content = 'auth/auth/general_message'; 
      $this->load->view('includes/template', array('message' => $message, 'main_content' =>$main_content)); 
     } else { 
      redirect('auth/login/'); 
     } 
    } 

    /** 
    * Login user on the site 
    * 
    * @return void 
    */ 
    function login() 
    { 
     if ($this->tank_auth->is_logged_in()) {         // logged in 
      redirect('admin'); 

     } elseif ($this->tank_auth->is_logged_in(FALSE)) {      // logged in, not activated 
      redirect('auth/send_again/');........ 

내가 로그인 스크립트를 보호하려는 컨트롤러/모듈 :

<?php 

if (!defined('BASEPATH')) 
    exit('No direct script access allowed'); 

    class Admin extends MX_Controller { 

     public function __construct(){ 
      parent::__construct(); 



      modules::run('auth/auth/login'); 

     } 

위의 내용이 작동하지 않는 것 같습니까? 내가 뭘 놓치고 있니?

+0

난 당신이'ELSEIF의 출력을 확인할 필요가 있다고 생각 ($ this-> tank_auth-> is_logged_in (FALSE))'. 이것이 true로 평가되지 않으면 사용자가 리디렉션되지 않으며 (로그인 확인에도 실패하더라도) 아무런 조치도 취하지 않아 사용자가 관리자 페이지에 남습니다. – Olaf

+0

감사합니다 olaf, 만약 내가 실행하려고하는 모듈을 테스트 할 수있는 방법은 :: 그것은 목표 함수를 찾는 것입니까 ?? – hairynuggets

답변

4

내가 내 컨트롤러에이 코드를 넣어 :

function _remap($method) 
{ 
    if (method_exists($this, $method) && $this->tank_auth->is_logged_in()) 
    { 
     $this->$method(); 
    } 
    else 
    { 
     redirect('/auth/login/'); 
    } 
} 
관련 문제