Codeigniter needs to connect from one module to another

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 the dashboard module and use a function inside the dashboard module. Just switch from my login module to my panel module. Here are my input controllers and my panel 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 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 panel module has a function called home that I am trying to connect and use. And the dashboard home function has a connection to another module, but I can't get the connection from the dashboard login to work. Also, the way my login works, I need to connect to the dashboard module via my members_area function. All help is greatly appreciated.

+3


source to share


1 answer


Assuming you are using this library

From the controller, you can use Modules::load

either$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 it helps

+1


source







All Articles