如何解决CodeIgniter 404未找到的错误?

时间:2016-02-26 09:57:07

标签: php .htaccess codeigniter restful-url

如何解决codeigniter中的404 error 这是我的控制器 /controller/api.php

<?php defined('BASEPATH') OR exit('no direct script access allowed');
require(APPPATH.'libraries/REST_Controller.php');

class api extends REST_Controller
{
     function __construct(){
        parent::__construct();
     }

    //------------------------ Constants --------------------------
 function student_get(){
  $student= $array = array(1=>array ('first' => 'ghali','Last_name'=>'aaaa' )
                            2=>array ('first' => 'aaaa' ,'Last_name'=>'bbbb' )
    );
  echo $student;
  $this->response($student);

 }

?>

我的 .htaccess 是:

<IfModule mod_rewrite.c>
  RewriteEngine On
  # !IMPORTANT! Set your RewriteBase here and don't forget trailing and leading
  #  slashes.
  # If your page resides at
  #  http://www.example.com/mypage/test1
  # then use
  # RewriteBase /mypage/test1/
  RewriteBase /
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

<IfModule !mod_rewrite.c>
  # If we don't have mod_rewrite installed, all 404's
  # can be sent to index.php, and everything works as normal.
  # Submitted by: ElliotHaughin

  ErrorDocument 404 /index.php
</IfModule>

点击网址 localhost / api / index.php / api / student 它返回404错误

1 个答案:

答案 0 :(得分:0)

表示: - http://localhost/api/index.php/api/student您的代码应该看起来像......

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

class api extends MY_Controller
{
 function __construct()
 {
    parent::__construct();
 }

    //------------------------ Constants --------------------------
 function student()
  {
  $student= $array = array(1=>array ('first' => 'ghali','Last_name'=>'aaaa' )
                            2=>array ('first' => 'aaaa' ,'Last_name'=>'bbbb' )
    );
  print_r( $student);

 }
}