douzhun5971 2011-11-25 13:28
浏览 71
已采纳

如何在Codeigniter HMVC中调用模块功能? 坦克认证

I have installed tank auth to save me time creating a authentication script.

As I am using HMVC, tank auth has it's own module (modules/auth).

How can I protect my other modules (/admin, /members etc) with the login script??

From what I have read I need to do something like:

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

My auth controller looks like:

<?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/');........

an the controller/module I want to protect with the login script:

<?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'); 

        }   

The above does not seem to work? What am I missing?

  • 写回答

1条回答 默认 最新

  • douhe3313 2011-12-09 14:19
    关注

    I put this code into my controllers:

    function _remap($method)
    {
        if (method_exists($this, $method) && $this->tank_auth->is_logged_in())
        {
            $this->$method();
        }
        else
        {
            redirect('/auth/login/');
        }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 腾讯云如何建立同一个项目中物模型之间的联系
  • ¥30 VMware 云桌面水印如何添加
  • ¥15 用ns3仿真出5G核心网网元
  • ¥15 matlab答疑 关于海上风电的爬坡事件检测
  • ¥88 python部署量化回测异常问题
  • ¥30 酬劳2w元求合作写文章
  • ¥15 在现有系统基础上增加功能
  • ¥15 远程桌面文档内容复制粘贴,格式会变化
  • ¥15 这种微信登录授权 谁可以做啊
  • ¥15 请问我该如何添加自己的数据去运行蚁群算法代码