用户
 找回密码
 入住 CI 中国社区
搜索
查看: 1637|回复: 0
收起左侧

[版本 3.x] codeigniter-restserver 无法正常 work

[复制链接]
发表于 2016-1-25 17:29:26 | 显示全部楼层 |阅读模式
最近因为要用到restful api 的开发方式,
想起 ci 有 codeigniter-restserver
于是就载来用用看,结果好像没有work 起来....

我照著作者https://github.com/chriskacerguis/codeigniter-restserver 上的教学,
先把相对应该的档案,加入CI的目录下,
然后执行 http://localhost/api/example/users
但却出现 404 error 画面

去查 log 档,出现
ERROR - 2016-01-25 15:50:37 --> 404 Page Not Found: api/Example/users
的错误讯息





看起来像是routes 跑错,但我routes.php 依官方的范例这样写
PHP复制代码
 
$route['default_controller'] = 'welcome';
$route['404_override'] = '';
$route['translate_uri_dashes'] = TRUE;
/*
| -------------------------------------------------------------------------
| Sample REST API Routes
| -------------------------------------------------------------------------
*/

$route['api/example/users/(:num)'] = 'api/example/users/id/$1'; // Example 4
$route['api/example/users/(:num)(\.)([a-zA-Z0-9_-]+)(.*)'] = 'api/example/users/id/$1/format/$3$4'; // Example 8
 
复制代码






但还是404 error,请问这是什么样的问题?
我的开发环境:
OS: XUbuntu 15.10
web server:nginx/1.9.3 (Ubuntu)
php-fpm: PHP 5.6.11-1ubuntu3.1

我 nginx 相关设定
PHP复制代码
 
 
server {
   listen 80;
   listen [::]:80;
 
   server_name testhost;
 
   root /path/testhost;
   autoindex on;
   index index.php index.html;
 
   # set expiration of assets to MAX for caching
  location ~* \.(ico|css|js|gif|jpe?g|png)(\?[0-9]+)?$ {
      expires max;
      log_not_found off;
   }
 
   location / {
      try_files $uri $uri/ /index.php;
   }
 
   if ($request_uri ~* index/?$)
       {
     rewrite ^/(.*)/index/?$ /$1 permanent;
        }
 
   if (!-d $request_filename)
       {
           rewrite ^/(.+)/$ /$1 permanent;
        }
 
   if ($request_uri ~* ^/system)
   {
      rewrite ^/(.*)$ /index.php?/$1 last;
      break;
  }
 
   if (!-e $request_filename)
  {
      rewrite ^/(.*)$ /index.php?/$1 last;
      break;
  }
 
   error_page 404 /index.php;
 
   location ~* \.php$  {
            #try_files $uri =404;
           include /etc/nginx/fastcgi_params;
                  include fastcgi.conf;
            fastcgi_pass 127.0.0.1:9000;
            fastcgi_index index.php;
            fastcgi_param SERVER_NAME $host;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
 
        }
 
   location ~ /\.ht {
      deny all;
   }
}
 
复制代码





本版积分规则