简体   繁体   English

如何检查控制器超薄框架中的URL

[英]How to check the url in the controller slim-framework

I have problem with slim slim有问题

I have the controllar, and 2 routs send to this controller. 我有控制者,并且有2条溃败发送给该控制器。

  1. The page html with teig. 带有teig的html页面。
  2. The api and show that in json. API,并在json中显示。

Now I need to check, if I request with this url: /product/{slug} 现在,我需要检查是否需要以下网址: /product/{slug}

return the twig (I do the return). 退回树枝(我退货)。

and if I request to url: api/product/{slug} return me the json (i do the return). 如果我请求url: api/product/{slug}我返回json(我会返回)。

now I don't know how to the the if request. 现在,我不知道如何处理if要求。 and how I just to know check what url request that controller. 以及我如何知道检查哪个URL请求该控制器。

$request->getUri()->getPath() will give you the current URL. $request->getUri()->getPath()将为您提供当前URL。

$request->getAttribute('route') will give you the current Route object. $request->getAttribute('route')将给您当前的Route对象。

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

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