codeigniter通话功能的控制器没有的index.php [英] Codeigniter call Function in Controller without index.php

查看:235
本文介绍了codeigniter通话功能的控制器没有的index.php的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道有那么多帖子concering这个问题。我什么都试过,但没有成功。

我用XAMPP V3.2.2在我的Windows 10的机器。在我的htdocs我得到了一个名为mysite的项目。在那里,我有codeigniter 3.0.3。

的config.php

  $配置['BASE_URL'] ='的http://本地主机/ mysite的/';$配置['index_page'] ='';

routes.php文件

  $路线['default_controller'] ='CI_home';

控制器CI_home.php:

 类CI_home扩展是CI_Controller {    功能__construct(){
        父:: __构造();
    }    公共功能指数($ LANG =''){
        $这个 - >负载>帮手(URL);
        $这个 - >负载>帮手('语言');
        $这个 - >朗GT&;负载($ LANG,$ LANG);
        $这个 - >负载>查看('view_home');
    }
}

当我称之为的http://本地主机/ mysite的,页面显示正确。

问题是,当我尝试的http://本地主机/ mysite的/ EN 的http://本地主机/ mysite的/指数/恩我从XAMPP收到了404。

但是,如果我尝试 HTTP://localhost/mysite/index.php/CI_home/index/en 它工作正常。

我做错了吗?我怎样才能删除CI_home /指数?

HTTP://localhost/mysite/.htaccess:

的.htaccess

  RewriteEngine叙述在
的RewriteCond $ 1 ^(指数\\ .PHP |资源|机器人\\ .txt)的!
的RewriteCond%{} REQUEST_FILENAME!-f
的RewriteCond%{} REQUEST_FILENAME!-d
重写规则^(。*)$的index.php / $ 1 [L,QSA]

如果启用了mod_rewrite我已经选中。

请帮帮我!

在此先感谢,
yab86


解决方案

尝试以下

这htaccess的

 选项+的FollowSymLinks
选项​​-Indexes
的DirectoryIndex index.php文件
RewriteEngine叙述上
的RewriteCond $ 1 ^(指数\\ .PHP |图片|机器人\\ .txt)的!
的RewriteCond%{} REQUEST_FILENAME!-f
的RewriteCond%{} REQUEST_FILENAME!-d
重写规则^(。*)$的index.php / $ 1 [L,QSA]

请在你的主目录下肯定htaccess的。

然后设置您的基本网址

  $配置['BASE_URL'] ='的http://本地主机/ yourproject /';

然后取出的index.php

  $配置['index_page'] ='';


  

注意: codeigniter 3个版本是区分大小写的。 确保只有首字母上层阶级和文件名的情况下


 < PHP类Ci_home扩展是CI_Controller {    公共职能__construct(){
         父:: __构造();
    }     公共功能指数($ LANG =''){
       $这个 - >负载>帮手(URL);
       $这个 - >负载>帮手('语言');
       $这个 - >朗GT&;负载($ LANG,$ LANG);
       $这个 - >负载>查看('view_home');
     }
}

然后确保文件名是Ci_home.php

那么你的默认路由应该是

在使用默认的控制器确保是相同的名称作为您选择的控制器。

URI路由

  $路线['default_controller'] ='ci_home';$路线['(:任何)'] ='ci_home /指数/ $ 1';

I know there are so many posts concering that problem. I tried everything, but without success.

I use xampp v3.2.2 on my windows 10 machine. In my htdocs I got a project called mysite. In there I have codeigniter 3.0.3.

config.php

$config['base_url'] = 'http://localhost/mysite/';

$config['index_page'] = '';

routes.php

$route['default_controller'] = 'CI_home';

Controller CI_home.php:

class CI_home extends CI_Controller{

    function __construct() {
        parent::__construct();
    }

    public function index($lang = ''){
        $this->load->helper('url');
        $this->load->helper('language');
        $this->lang->load($lang, $lang);
        $this->load->view('view_home');
    }
}

When I call http://localhost/mysite, the page is shown correctly.

The problem is, when I try to http://localhost/mysite/en or http://localhost/mysite/index/en I received a 404 from xampp.

But if I try http://localhost/mysite/index.php/CI_home/index/en it works fine.

What I am doing wrong? How can I remove the "CI_home/index"?

http://localhost/mysite/.htaccess:

.htaccess

RewriteEngine On
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]

I already checked if the mod_rewrite is enabled.

Please help me!

Thanks in advance, yab86

解决方案

Try this htaccess below

Options +FollowSymLinks
Options -Indexes
DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]

Make sure htaccess in your main directory.

Then set your base url

$config['base_url'] = 'http://localhost/yourproject/';

Then remove index.php

$config['index_page'] = '';

Note: Codeigniter 3 versions are case sensitive. Make sure only the first letter upper case of class and file name.

<?php

class Ci_home extends CI_Controller {

    public function __construct() {
         parent::__construct();
    }

     public function index($lang = '') {
       $this->load->helper('url');
       $this->load->helper('language');
       $this->lang->load($lang, $lang);
       $this->load->view('view_home');
     }
}

Then make sure file name is Ci_home.php

Then your default route should be

When using default controller make sure is the same name as the controller you choose.

URI Routing

$route['default_controller'] = 'ci_home';

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

这篇关于codeigniter通话功能的控制器没有的index.php的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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