简体   繁体   中英

How to check the url in the controller slim-framework

I have problem with slim

I have the controllar, and 2 routs send to this controller.

  1. The page html with teig.
  2. The api and show that in json.

Now I need to check, if I request with this url: /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).

now I don't know how to the the if request. and how I just to know check what url request that controller.

$request->getUri()->getPath() will give you the current URL.

$request->getAttribute('route') will give you the current Route object.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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