【问题标题】:How do I solve CodeIgniter's 404 not found error?如何解决 CodeIgniter 的 404 not found 错误?
【发布时间】:2016-02-26 09:57:06
【问题描述】:

如何解决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>

当我点击 url localhost/api/index.php/api/student 它返回 404 错误

【问题讨论】:

  • 试试http://localhost/api/index.php/api/student_get

标签: php .htaccess codeigniter restful-url


【解决方案1】:

for :- 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);

 }
}

【讨论】:

  • 是的,我的应用程序的名称是 localhost 中的 api
  • 用我更新的代码尝试http://localhost/api/index.php/api/student...您的代码不起作用,因为您将api 类扩展为rest 控制器,因此url http://localhost/api/index.php/rest/student_get 将与您的代码一起使用...因为echo $student而发出警告... :)
  • 知道我有消息:语法错误,意外'?>',期待函数(T_FUNCTION)
  • @choofstoon 我的代码给你这个错误Message: syntax error, unexpected '?&gt;', expecting function (T_FUNCTION) ??
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-02-20
  • 2017-09-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-05-23
相关资源
最近更新 更多