codeigniter + HMVC + REST [英] Codeigniter + HMVC + REST
问题描述
我的工作codeigniter +基于HMVC应用程序,我想添加一个新的模块。我用菲尔鲟鱼的 REST_Controller 2.6.0 和格式库创建一个REST API作为一个模块。
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.
当我试图让例如 http://api.example.com/user/ ID / 1 / 或 http://api.example.com/用户/ ID / 1 /格式/ JSON 我gеt以下错误:
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
在我的 routes.php文件我有这样的:
$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:
application
--modules
----api
------config
------controller
芬利,我用的是默认的配置,我没有改变任何东西。在 autoload.php 格式库自动加载。任何想法?
Finlay, I use the default configurations and I didn't change anything. The Format library is auto loaded in autoload.php. Any ideas?
推荐答案
您需要更改Rest_Controller延长HMVC的MX_Controller而非是CI_Controller。
You need to change Rest_Controller to extend HMVC's MX_Controller rather than CI_Controller.
这篇关于codeigniter + HMVC + REST的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!