The function call gives me 404 pages in codeigniter

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

  • attachment /
    • Controllers /
      • admin /
        • admin.php

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 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";
0
source share
4 answers

There is a segment in your application directory admin. 1. Folder (/ admin /), 2. File (admin.php)

URL should be like http://my-local-project.com/admin/admin/logout

, :

$route['admin']        = "admin/admin/index";
$route['admin/(:any)'] = "admin/admin/$1";

CodeIgniter - HMVC:

https://bitbucket.org/wiredesignz/codeigniter-modular-extensions-hmvc

0

, URL.

public function logout()
{
    $userSessionData = array(
        'user_id' => '',
        'username' => '',
        'email' => ''
    );
    $this->session->unset_userdata($userSessionData);// unset your sessions
    $this->session->sess_destroy();   
    redirect('admin/index');     // redirect to admin index page
}
0

...

$this->session->sess_destroy();
redirect('controller/method');
0

:

$route ['logout'] = "admin/admin/logout";

$route ['admin'] = "admin/admin ';

logout logout" >

admin → admin class → logout

, , redirect ('admin'), ( )

, :)

0

Source: https://habr.com/ru/post/1656043/


All Articles