【问题标题】:Codeignite hello world code in docs doent work文档中的 Codeigniter hello world 代码不起作用
【发布时间】:2017-09-01 00:51:45
【问题描述】:

我刚开始使用 CodeIgniter,却被文档中的 hello world 代码卡住了。每次我在 url 栏中输入博客控制器的名称并按 Enter 时,都会出现以下错误: 404 Error Page Not Found!

localhost/php/CodeIgniter/.htaccess

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



route.php

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


config.php

$config['base_url'] = 'http://localhost/php/CodeIgniter/';
$config['index_page'] = 'index.php';


controllers/Blog.php

<?php
    class Blog extends CI_Controller {

            public function index()
            {
                    echo 'Hello World!';
            }
    }

我该如何解决这个问题?

【问题讨论】:

    标签: php codeigniter


    【解决方案1】:

    您必须在 [route.php] 对应的控制器类/方法上设置一个 URL 字符串。

    $route['default_controller'] = 'blog/index';
    $route['blog/(:any)'] = 'blog/show/$1'
    

    您可以将引用“/”的 URL“http://localhost/”保留为 route.php 上 default_controller 的主页

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

    请浏览更多关于 .htaccess 和友好 URL 的信息。如果您收到 404 错误,可能是您的网址不友好。

    友好:

    http://localhost/blog/lorem-ipsum
    

    不友好:

    http://localhost/index.php/blog/lorem-ipsum
    

    文档:https://www.codeigniter.com/userguide3/general/routing.html

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-12-08
      • 2013-09-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-15
      • 2019-05-01
      相关资源
      最近更新 更多