【问题标题】:No URI present. Default controller set. Codeigniter 3.1.9 and PHP 7.0不存在 URI。默认控制器集。 Codeigniter 3.1.9 和 PHP 7.0
【发布时间】:2019-01-31 06:47:03
【问题描述】:

我的路由不工作。

我用 - https://github.com/bcit-ci/CodeIgniter/wiki/Removing-index.php-from-a-URL-path-in-XAMPP-for-Windows 删除了 index.php

我正在使用以下设置。 Codeigniter 3.1.9 的新副本

config.php

$config['base_url'] = 'http://localhost/CodeIgniter-3.1.9/';
$config['index_page'] = '';

.htaccess

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>

routes.php

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

控制器 - Hello.php

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

class Hello extends CI_Controller {

    public function __construct(){
        parent::__construct();
    }
    public function index()
    {
        echo("Hello - index");
        $this->load->view('welcome_message');
    }

    public function hello(){
        echo("hello");
        $this->load->view('welcome_message');
    }
}

当我导航到 http://localhost/CodeIgniter-3.1.9/hello 时,它正在加载 Welcome 控制器。

日志

DEBUG - 2018-08-24 18:56:47 --> UTF-8 Support Enabled
DEBUG - 2018-08-24 18:56:47 --> No URI present. Default controller set.
DEBUG - 2018-08-24 18:56:47 --> Global POST, GET and COOKIE data sanitized
DEBUG - 2018-08-24 18:56:47 --> Total execution time: 0.0227

【问题讨论】:

  • 您应该使用http://localhost/hello 网址吗?
  • 那不是项目工程路径。

标签: codeigniter codeigniter-3


【解决方案1】:

去掉base_url末尾的斜杠

$config['base_url'] = 'http://localhost/CodeIgniter-3.1.9';

【讨论】:

    【解决方案2】:

    那是我的错,我在配置中打开了$config['enable_query_strings'] = TRUE;,这就是它导致问题的原因。当我阅读核心 uri.php 文件时,它有以下评论。

    // If query strings are enabled, we don't need to parse any segments.
            // However, they don't make sense under CLI.
            if (is_cli() OR $this->config->item('enable_query_strings') !== TRUE)
    

    我设置$config['enable_query_strings'] = FALSE; 然后一切正常。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-09-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多