dongpao9165
2017-05-26 19:19
浏览 46
已采纳

如何向android / ios应用程序提供symfony内容?

I plan to add access to android & ios developers to content form Symfony 3 data. Now, access is by web browser. I've expanded logic on Controller but sharing is simple by TWIG/HTML pages. 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.

What do I have to add to controller/function to doing it?

图片转代码服务由CSDN问答提供 功能建议

我计划添加对android& amp;的访问权限 ios开发人员将内容形成Symfony 3数据。 现在,通过Web浏览器进行访问。 我在Controller上扩展了逻辑,但TWIG / HTML页面的共享很简单。 ex。

  / ** 
 * Class DefaultController 
 * 
 * @Route(“/ item”)
 * 
 * @package SameBundle \ Controller  
 * / 
class DefaultController扩展Controller 
 {
 / ** 
 *列出所有产品实体。
 * 
 * @Route(“/”,name =“product_index”)
 * @Method(  “GET”)
 * 
 * @Template 
 * / 
公共函数indexProductAction()
 {
 //(...)
 
 return ['products'=>  $ products,]; 
} 
   
 
 

indexProduct.html.twig页面支持它。

我需要添加到控制器/功能中才能执行此操作?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dousi5501 2017-05-26 19:46
    已采纳

    To server mobile devices you will need to send them json instead of 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:

    return new JsonResponse($myresponse);
    
    点赞 评论

相关推荐 更多相似问题