douduoting8408 2015-07-11 14:53
浏览 27

Codeigniter需要从一个模块连接到另一个模块

I want to connect from one controller in one module to another controller in another module. I want to go from my login module to my dashboard module and use a function inside the dashboard module. Just basically switch from my login module to my dashboard module. Here is my login controllers and my dashboard controller.

class Login extends MX_Controller {

function index()
{
        $this->load->view('includes/header');
        $this->load->view('login_form');
        $this->load->view('includes/footer');       
}

function validate_credentials()
{       
        $this->load->model('membership_model');
        $query = $this->membership_model->validate();

        if($query) // if the user's credentials validated...
        {
                $data = array(
                        'username' => $this->input->post('username'),
                        'is_logged_in' => true
                );
                $this->session->set_userdata($data);
                redirect('login/site/members_area');
        }
        else  // incorrect username or password
        {
                $this->index();
        }
}   

function signup()
{
        //$data['main_content'] = 'signup_form';
        //$this->load->view('includes/template', $data);
        $this->load->view('includes/header');
        $this->load->view('signup_form');
        $this->load->view('includes/footer');
}

function create_member()
{
        $this->load->library('form_validation');

        // field name, error message, validation rules
        $this->form_validation->set_rules('first_name', 'Name', 'trim|required');
        $this->form_validation->set_rules('last_name', 'Last Name', 'trim|required');
        $this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email|callback_check_if_email_exists');
        $this->form_validation->set_rules('username', 'Username', 'trim|required|min_length[4]|max_length[15]|callback_check_if_username_exists');
        $this->form_validation->set_rules('password', 'Password', 'trim|required|min_length[4]|max_length[32]');
        $this->form_validation->set_rules('password2', 'Password Confirmation', 'trim|required|matches[password]');


        if($this->form_validation->run() == FALSE) // didn't validate
        {
                $this->load->view('includes/header');
                $this->load->view('signup_form');
                $this->load->view('includes/footer');
        }

        else
        {           
                $this->load->model('membership_model');

                if($query = $this->membership_model->create_member())
                {
                        $data['account created'] = 'Your account has been created. <br /> <br /> You may now login';

                        $this->load->view('includes/header');
                        $this->load->view('signup_successful', $data);
                        $this->load->view('includes/footer');

                }
                else
                {
                        $this->load->view('includes/header');
                        $this->load->view('signup_form');
                        $this->load->view('includes/footer');   
                }
        }

}

        function check_if_username_exists($requested_username) 
{
        $this->load->model('membership_model');

        $username_available = $this->membership_model->check_if_username_exists($requested_username);

                if ($username_available) 
                {
                                return TRUE;
                }else{
                                return FALSE;
                }
}

function check_if_email_exists($requested_email) 
{
        $this->load->model('membership_model');

        $email_available= $this->membership_model->check_if_email_exists($requested_email);

                if ($email_available) 
                {
                                return TRUE;
                }else{
                                return FALSE;
                }
}



function logout()
{
        $this->session->sess_destroy();
        $this->index();
}

}


my second login controller



class Site extends MX_Controller {

public function __construct()
    {
    parent::__construct();
         $this->is_logged_in();
              $this->lang->load('login/login/', 'english');
     }

function members_area()
{
         $this->load->view('logged_in_area');

                       //$this->load->module('dashboard/dashboard');

                       //$this->load->view('home');
}


function is_logged_in()
{
                        $is_logged_in = $this->session->userdata('is_logged_in');
                        if(!isset($is_logged_in) || $is_logged_in != true)
                       {
                               echo 'You don\'t have permission to access this page. <a href="../login">Login</a>'; 
                               die();       
                               //$this->load->view('login_form');
                       }        
}   

}

the controller in my dashboard module has a function called home I am trying to connect to and use. And the home function of the dashboard has a connection to another module but I cannot get the connection from login to dashboard to work. Also the way my login works I need to connect to the dashboard module through my members_area function. All help greatly appreciated.

  • 写回答

1条回答 默认 最新

  • dongque3797 2015-07-11 15:06
    关注

    Assuming you're using this library

    From controller you can use Modules::load or $this->load-module

    $moduleInstance = $this->load->module('yourmodule');
    // or
    $moduleInstance = Modules::load('yourmodule');
    
    // Now you can call any public module controller method
    $moduleInstance->somePublicMethod($arg1, $argn);
    // you can also use $this->yourmodule as a model instance
    

    Hope this helps

    评论

报告相同问题?

悬赏问题

  • ¥15 MATLAB动图问题
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题