调用函数给我在codeigniter的404页面 [英] Calling a function gives me 404 page in codeigniter

查看:126
本文介绍了调用函数给我在codeigniter的404页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从一个视图调用我的控制器的注销功能。
只是为了抬头,我已经做了我的项目的模块化结构,当我去 http://my-local-project.com/admin 它加载我的管理控制器的索引功能。但是当我去 http://my-local-project.com/admin/logout ,它显示我404页
我的目录结构是

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 /

    • 控制器/

      • admin /

        • admin.php

        控制器:

            <?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

        EDIT my routes.php is

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


        推荐答案

        您的应用程序目录有2 admin 段。 1.文件夹(/ admin /),2.文件(admin.php)

        Your app directory have 2 admin segment. 1. Folder(/admin/), 2. File (admin.php)

        URL应该像 http:// my- project.com/admin/admin/logout

        如果你不想这样,你必须设置路线:

        If you dont want like this, you have to set routes:

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

        或使用CodeIgniter模块扩展 - HMVC:

        Or use CodeIgniter Modular Extensions - HMVC:

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

        这篇关于调用函数给我在codeigniter的404页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆