Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check the url in the controller slim-framework

Tags:

url

php

slim

slim-3

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.

like image 673
HaiZone Avatar asked Dec 29 '25 13:12

HaiZone


1 Answers

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

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

like image 156
Rob Allen Avatar answered Dec 31 '25 04:12

Rob Allen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!