【问题标题】:Using Zend_Rest_Controller for Web service in Zend Framework在 Zend Framework 中为 Web 服务使用 Zend_Rest_Controller
【发布时间】:2013-03-31 20:18:15
【问题描述】:

当我从 Zend_Rest_Controller 扩展一个类时,实现了 5 个抽象方法(index、get、put、delete、post),用于 CRUD。

我的项目结构是

 -application
     - config
     - controllers       // used for our web controllers
     - emails
     - forms
     - views
     -Bootstrap.php
-library
  -CustomLibrary // Libraries for our project
  -Frontend
   -Action.php //this is extends Zend_Action_Controller and I added some customize code

我想为我的应用程序创建一个 Web 服务,以便在我们的 Android 应用程序上使用它,我想为 Android 应用程序返回 JSON 对象和参数。 我研究并询问了stackoverflow,我发现Rest Controller是使用它的方式。 我的问题: 在这种情况下使用 Zend_Rest_Controller 是否正确?
- 如果是,我不能写更多的动作,我只使用抽象的动作,我需要的不仅仅是那些动作,比如(registerAction()、getAllNewsAction() 等......) 还是我应该为此使用更多的类?


如果没有,用什么?以及将这些 api 类放在哪里(在同一个控制器文件夹中或放在 Library 文件夹中)

【问题讨论】:

    标签: zend-framework zend-rest


    【解决方案1】:

    如果您使用 RESTful 架构,您总是有以下 GET-、POST-、PUT-、DELETE-操作之一。在 ZF2 中,这意味着您在 Controller-Class 中实现了以下操作:indexAction (GET-Request)、getAction (GET-Request)、postAction (POST-Request)

    您需要的其他方法是通过您传递给上述请求的参数来控制的。看看这个教程:http://www.techchorus.net/create-restful-applications-using-zend-framework

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-24
      • 1970-01-01
      • 1970-01-01
      • 2016-06-25
      • 2012-06-10
      相关资源
      最近更新 更多