2

如果我将默认控制器留在 routes.php 文件“欢迎”中,则 CI 3.0 有问题,一切正常。但是,如果我更改它,即“主”CI 开始抛出 404 错误,主控制器的第一步与欢迎相同。我只是复制文件。重命名,更改类名(当然),并在index()加载视图中。有什么建议么?

我也忘了告诉 wamp localhost 一切都在工作..但在服务器中不是..:/

还有一件事......即如果我尝试去 mydomain.com/welcome - 工作,如果我尝试去 mydomain.com/main - 不是。即使我将路由默认控制器更改回欢迎

我的 main.php 文件:

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Main extends CI_Controller {
    function index(){
        $this->load->view('welcome_message');
    }
}

我的 routes.php 文件:

<?php

defined('BASEPATH') OR exit('No direct script access allowed');

$route['default_controller'] = 'main';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
4

5 回答 5

7

正如评论中所说:您的控制器的文件名必须以大写字母开头。在您的情况下,Main.php。请参阅http://codeigniter.com/userguide3/changelog.html

«更改了文件命名约定(类文件名现在必须是 Ucfirst,其他所有内容都必须小写)。»

于 2015-02-03T15:12:43.157 回答
4

您只需要将默认控制器设置application/config/routes.php

$route['default_controller'] = $this->set_directory('front/home/').'home/index';

对于 Ci 3.x

于 2017-12-24T06:21:29.090 回答
1

我坚持这个问题。我修复了它只是替换了路径。如果你想使用 CI,这里的“site”文件夹是默认的,你必须将所有代码存储到“site”文件夹中。如果您没有使用站点文件夹进行安装,它将不适用于多控制器设置。因此,您将默认控制器作为可行的,而其他控制器则出现 404。

更改根目录中的 .htacess 文件。

<IfModule mod_rewrite.c>
        RewriteEngine On
        RewriteBase /

        # Removes index.php from ExpressionEngine URLs
        RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
        RewriteCond %{REQUEST_URI} !/system/.* [NC]
        RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,NE,L]

        # Directs all EE web requests through the site index file
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
       # RewriteRule ^(.*)$ /site/index.php/$1 [L]
        RewriteRule ^(.*)$ /codeig/index.php/$1 [L]
</IfModule>

上面你可以看到
RewriteRule ^(.*)$ /codeig/index.php/$1 [L] “codeig”根文件夹的行发生了变化。

于 2016-07-19T09:37:28.413 回答
0

尝试将其更改function index()Public。如果这不起作用,请尝试添加 URL:domain.com/index.php/main查看会发生什么。有时您需要在另一台服务器中使用 .htaccess 来删除index.php

于 2015-02-03T15:09:47.717 回答
0

在 Codeigniter 3 中,他们添加了额外的代码来强制文件名以大写字母开头。这是对此的修复。

system/core/Router.php换线(约303

if ( ! file_exists(APPPATH.'controllers/'.$this->directory.ucfirst($class).'.php'))

if ( ! file_exists(APPPATH.'controllers/'.$class.'.php'))

我也必须删除里面的CodeIgniter.php东西Loader.php

于 2016-08-15T17:58:59.317 回答