【问题标题】:codeigniter controller loadingcodeigniter 控制器加载
【发布时间】:2012-08-12 06:19:06
【问题描述】:

我的本​​地主机中有一个名为 blog.php 的控制器。要访问它,我在地址栏中键入 http://localhost/ci/index.php/blog。在教程中它说它将显示 Hello World 但我得到的显示是一个包含 blog.php 代码和 404 Page Not Found 的页面。

这里是代码。

*<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Blog extends CI_Controller {
    /**
     * Index Page for this controller.
     *
     * Maps to the following URL
     *      http://example.com/index.php/blog
     *  - or -  
     *      http://example.com/index.php/blog/index
     *  - or -  
     * So any other public methods not prefixed with an underscore will
     * map to /index.php/blog/<method_name>
     * @see http://codeigniter.com/user_guide/general/urls.html
     */
    public function index()
    {
        echo "Hello World";
    }
}
/* End of file Blog.php */
/* Location: ./application/controllers/blog.php */*

请大家帮我看看有什么问题。

【问题讨论】:

  • 能否贴出config/config.php文件代码? localhost/ci 还在工作吗?它显示什么?而且你没有在 PHP 之前使用 *,对吧?
  • 是的 Mr.web 是对的。你在 ci 文件夹中的 codeigniter 文件?尝试在 google 或 SO 搜索同样的问题,你会发现很多问题和答案。

标签: php codeigniter controller load


【解决方案1】:

您使用的是哪个版本的 CodeIgniter,因为 CI_Controller 用于 CI 上的旧版本。你有没有尝试过

class Blog extends Controller {
}

class Blog extends MY_Controller {
}

MY_ 在您的 config.php 文件中设置的位置。

【讨论】:

  • 其实不然。 CI 使用 CI_Controller 仍高达 2.1.4。 MY_ 用于创建自己的类而不是控制器/视图/模型
猜你喜欢
  • 2011-08-30
  • 1970-01-01
  • 1970-01-01
  • 2017-04-15
  • 2015-03-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多