【问题标题】:How serve symfony content to android/ios apps?如何为 android/ios 应用程序提供 symfony 内容?
【发布时间】:2017-10-27 18:33:21
【问题描述】:

我计划向 android 和 ios 开发人员添加对 Symfony 3 数据形式的内容的访问权限。现在,访问是通过网络浏览器。我在控制器上扩展了逻辑,但通过 TWIG/HTML 页面共享很简单。 例如。

/**
* Class DefaultController
* 
* @Route("/item")
*
* @package SameBundle\Controller
*/
class DefaultController extends Controller
{
   /**
   * Lists all Product entities.
   *
   * @Route("/", name="product_index")
   * @Method("GET")
   *
   * @Template
   */
   public function indexProductAction()
   {
     // (...) 

     return ['products' => $products,];
}

indexProduct.html.twig 页面支持它。

我必须向控制器/功能添加什么才能做到这一点?

【问题讨论】:

  • 你应该做一个基于 JsonResponse 的 API,这样你就可以在 android 上解析它

标签: php android ios symfony web-applications


【解决方案1】:

对于服务器移动设备,您需要向它们发送 json 而不是 html。 因此,在您的控制器中,您可以检查请求是否来自浏览器,然后像往常一样返回 html,如果请求来自移动应用程序,则返回 json 响应:

return new JsonResponse($myresponse);

【讨论】:

    猜你喜欢
    • 2016-05-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多