Codeigniter + HMVC + REST [英] Codeigniter + HMVC + REST

查看:28
本文介绍了Codeigniter + HMVC + REST的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发基于 Codeigniter + HMVC 的应用程序,我正在尝试添加一个新模块.我使用 Phil Sturgeon 的 REST_Controller 2.6.0Format 库来创建 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/user/id/1/format/json 我收到以下错误:

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 中,我有这个:

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:

application
--modules
----api
------config
------controller

Finlay,我使用默认配置,我没有改变任何东西.格式库会自动加载到 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆