I call the function to exit my controller from the view. For heads-up, I created a modular structure for my project, and when I go to http://my-local-project.com/admin, it loads the index function of my controller-administrator. But when I go to http://my-local-project.com/admin/logout, it shows me 404 pages of my directory structure
Controller:
<?php
class Admin extends CI_Controller {
function __construct() {
parent::__construct();
$this->data = "";
$this->header = $this->load->view('admin/header', $this->data, TRUE);
$this->template = $this->load->view('admin/template', $this->data, TRUE);
$this->footer = $this->load->view('admin/footer', $this->data, TRUE);
$this->load->helper('url');
session_start();
}
public function index() {
echo "all is well";
}
public function logout() {
$userSessionData = array(
'user_id' => '',
'username' => '',
'email' => ''
);
$this->session->unset_userdata($userSessionData);
$this->session->sess_destroy();
session_destroy();
redirect(base_url('admin/login'));
exit;
}
}
?>
and here I want to call this function as follows
<a href="<?php echo site_url()?>admin/logout">Sign Out</a>
CHANGE
my routes.php
$route['default_controller'] = "welcome";
$route['admin(/:any)'] = "admin/admin$1";
source
share