I am calling a logout function of my controller from a view.
Just for heads up, I have made the modular structure of my project and when I go to http://my-local-project.com/admin, it loads the index function of my admin controller. But when i go to http://my-local-project.com/admin/logout, it shows me 404 page
my directory structure is
- application/
- Controllers/
- admin/
- admin.php
- admin/
- Controllers/
Controller:
<?php
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
* Description of TestController
*
* @author Ibm
*/
class Admin extends CI_Controller {
function __construct() {
parent::__construct(); //call to parent constructor
$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');
// $this->loginModel = $this->load->model('admin/loginModel');
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 like this
<a href="<?php echo site_url()?>admin/logout">Sign Out</a>
EDIT my routes.php is
$route['default_controller'] = "welcome";
$route['admin(/:any)'] = "admin/admin$1";