简体   繁体   English

如何将symfony内容提供给android / ios应用?

[英]How serve symfony content to android/ios apps?

I plan to add access to android & ios developers to content form Symfony 3 data. 我计划将对Android和ios开发人员的访问权限添加到内容表Symfony 3数据中。 Now, access is by web browser. 现在,可以通过Web浏览器进行访问。 I've expanded logic on Controller but sharing is simple by TWIG/HTML pages. 我已经在Controller上扩展了逻辑,但是通过TWIG / HTML页面进行共享很简单。 ex. 例如

/**
* 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,];
}

It is supported by the indexProduct.html.twig page. indexProduct.html.twig页面支持它。

What do I have to add to controller/function to doing it? 我必须在控制器/功能上添加些什么?

To server mobile devices you will need to send them json instead of html. 要为移动设备提供服务器,您需要向其发送json而不是html。 So in your controller you can check if the request comes from the browser then you return html as you do it usually, and if request comes from mobile app then return json response: 因此,在控制器中,您可以检查请求是否来自浏览器,然后像平常一样返回html,如果请求来自移动应用程序,则返回json响应:

return new JsonResponse($myresponse);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM