我想从一个模块中的一个控制器连接到另一个模块中的另一个控制器。我想从我的登录模块转到我的仪表板模块并使用仪表板模块中的一个函数。基本上只是从我的登录模块切换到我的仪表板模块。这是我的登录控制器和仪表板控制器。
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');
}
}
}
我的仪表板模块中的控制器有一个名为 home 的功能,我正在尝试连接和使用。仪表板的主页功能与另一个模块有连接,但我无法连接从登录到仪表板的工作。此外,我的登录方式也需要通过 members_area 函数连接到仪表板模块。非常感谢所有帮助。