2012-07-11 09:59
浏览 36

Codeigniter + HMVC + REST

I'm working on Codeigniter + HMVC based application and I'm trying to add a new module. I use Phil Sturgeon's REST_Controller 2.6.0 and Format libraries to create an REST API as a module.

When I try to get for example http://api.example.com/user/id/1/ or http://api.example.com/user/id/1/format/json I gеt the below error:

 A PHP Error was encountered
 Severity: Notice
 Message: Undefined property: Api::$format
 Filename: libraries/REST_Controller.php
 Line Number: 380

In my routes.php I have this:

 $route['user/id/(:num)/format/(:any)'] = "api/user/$1/format/$2";
 $route['user/id/(:num)'] = "api/user/$1";

The directory structure of the application is:


Finlay, I use the default configurations and I didn't change anything. The Format library is auto loaded in autoload.php. Any ideas?

图片转代码服务由CSDN问答提供 功能建议

我正在开发基于Codeigniter + HMVC的应用程序,我正在尝试添加一个新模块。 我使用Phil Sturgeon的 REST_Controller 2.6.0 格式库来创建REST API作为模块。

当我试图获取时 例如 http://api.example.com/user/id/1/ http://api.example.com/user/id/1/format/ json 我得到以下错误:

消息:未定义属性:Api :: $ format 
文件名 :libraries / REST_Controller.php 

在我的 routes.php 中我有: \ n

  $ route ['user / id /(:num)/ format /(:any)'] =“api / user / $ 1 / format / $ 2”; 
 $ route ['user  / id /(:num)'] =“api / user / $ 1”; 

应用程序的目录结构是: \ ñ

  - 的模块的
 ---- API 

Finlay,我使用默认配置和 我什么都没改变。 格式库在 autoload.php 中自动加载。 有什么想法吗?

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • doqau82086 2012-07-11 10:20

    You need to change Rest_Controller to extend HMVC's MX_Controller rather than CI_Controller.

    打赏 评论

相关推荐 更多相似问题