LoginSignup
1
0

More than 3 years have passed since last update.

php slimのRequestオブジェクトからリクエストURLの絶対URLを取得する

Posted at

困ったこと

PHPのSlim フレームワークで開発をしていてリクエストの絶対URLが取得したかった。

TL;DR

ストリングでキャストするとでてくる。

(string)$this->request->getUri();

経緯

slimで開発をしていて、ちょっとリクエストされたURIをセッションに保存して、別の処理をした後に、セッションから読み出して、リダイレクトで戻りたかった。

PSR-7のRequestオブジェクトが、こんな感じで、これを自分で結合していくのは面倒。

何かよい方法あるはずって探した。


‌‌> $this->request->getUri()
< Slim\Psr7\Uri::__set_state(array(
   'scheme' => 'https',
   'user' => '',
   'password' => '',
   'host' => 'example.com',
   'port' => 443,
   'path' => '/oauth2/authorize',
   'query' => 'state=xxxxxx',
   'fragment' => '',
))

キャストするだけだった(笑)

> ‌‌(string)$this->request->getUri()
< https://example.com/oauth2/authorize?state=xxxxx

参考文献

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0