CI新的默认控制器不起作用

问题描述 投票:0回答:5

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

我也忘了告诉wamp localhost一切正常..但在服务器上没有..:/

还有一件事......即如果我尝试去mydomain.com/welcome - 工作,如果我尝试去mydomain.com/main - NOT。即使我改变路线默认控制器回到欢迎

我的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;
php codeigniter codeigniter-3
5个回答
5
投票

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

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


1
投票

你只需要在application/config/routes.php中设置你的默认控制器

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

对于Ci 3.x


0
投票

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


0
投票

我坚持这个问题。我修复它只是替换路径。这里“site”文件夹是默认的,如果你想使用CI,你必须将你的所有代码存储到“site”文件夹中。如果您尚未使用站点文件夹进行安装,则它将无法与多个控制器设置一起使用。因此,您可以将默认控制器视为可行的,其他人则显示为404。

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

<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”根文件夹的行。


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.phpLoader.php中的东西。

© www.soinside.com 2019 - 2024. All rights reserved.