我正在开发基于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出现以下错误:
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";
应用程序的目录结构为:
application
--modules
----api
------config
------controller
Finlay,我使用默认配置,没有做任何更改。Format库是在autoload.php中自动加载的。有什么想法吗?
您需要更改Rest_Controller,以扩展HMVC的MX_Coontroller而不是CI_Controller。