我是 Zend 框架和 MVC 类型编程的新手(虽然不是 PHP),我正在尝试使用 Zend 框架为我的服务器上的数据提供 API 访问。
我使用 Chris Danielson 的文章 ( http://www.chrisdanielson.com/2009/09/02/creating-a-php-rest-api-using-the-zend-framework/ ) 作为基础。
我想提供对以下格式的数据的访问:
(a) http://www.example.com/api/createevent
Data will be POSTed here, success will return an id, otherwise an
error message/code
(b) http://www.example.com/api/geteventdetails/1234
GET request will return data
(c) http://www.example.com/api/getregistrationdetails/1234
GET request will return data
(d) http://www.example.com/api/getregistrationdetails/1234/567
GET request will return data
问题:
有一个默认文件位于 \api\application\controllers\VersionController.php ,它可以处理以下类型的 URL:http://www.example.com/api/version。我是否应该在以下位置创建一个单独的文件:\api\application\controllers\GeteventdetailsController.php 来处理类型 (b) 的请求(并且每个类型的请求都有一个)?如果没有,我应该在哪里放置我的代码来处理这些多种请求类型?
如何获取 (b) 到 (d) 中传递的参数?
要执行 (b) 到 (d) 的请求,我需要从服务器的数据库中获取信息。我应该将执行实际 MySQL 查询的代码放在哪里?