【问题标题】:Error:404 page not found, code igniter错误:404 页面未找到,codeigniter
【发布时间】:2015-03-30 17:11:11
【问题描述】:

controller.php

<?php

    define('_root',$_SERVER['DOCUMENT_ROOT']);
    include(_root.'/innoshop/application/models/model.php');

     // include_once 'model.php';

    class Controller {
     public $model;

     public function __construct()  
        {  
            $this->model = new Model();

        }

如果我输入 localhost:8888/projectname,我会得到这样的错误

 404 Page Not Found

The page you requested was not found.

谁帮帮我

【问题讨论】:

  • 嗯,你试过什么?
  • 8888 端口是否正确?你能打开 localhost:8888 吗?
  • 不知道你为什么这样做,你有没有考虑在应用程序/核心中创建一个核心文件,然后在 MY_Model.php 中创建一个核心文件
  • 我认为您应该更好地查看 codeigniter 的文档。您没有按应有的方式使用它。您的控制器必须扩展 CI_Controller 并包含一个 index() 函数。这也不是加载模型的好方法。 codeigniter.com/user_guide/overview/getting_started.html

标签: php codeigniter http-status-code-404


【解决方案1】:

正如人们所说,您应该阅读文档,因为这是非常错误的。要解决这个问题..

class Controller extends CI_Controller{//better to give your controller a more meaningful name

       public function __construct(){
           parent::__construct();
           //use the CI loader - the model will then be available like this $this->model->some_function();
           $this->load->model('model');//better to give your model a more meaningful name as well 
       }

       //the index method allows you to use just the controller name in your URI eg localhost:8888/projectname/index.php/controller 
       public function index(){
           echo 'something to see';
       }

        //an alternative controller method get it like localhost:8888/projectname/index.php/controller/your_method_name
        public function your_method_name(){
           echo 'something to see in your method';
        }

} 

如果你想摆脱 URI 中的 index.php,在 CodeIgniter 中搜索与 .htaccess 相关的问题

如果您希望能够使用像 localhost:8888/projectname 这样的 uri,那么您需要在 config/routes.php 中添加一个路由来定义像这样的默认控制器 $route['default']='controller';

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-03-09
    • 1970-01-01
    • 2016-12-06
    • 2015-07-28
    • 1970-01-01
    • 1970-01-01
    • 2015-10-07
    • 2015-05-19
    相关资源
    最近更新 更多