0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

cake php3 で$ _SERVERの値を取得する場合

Posted at

POST GETのどちらが呼ばれたのかを調べるため、コントローラーで
if ($_SERVER ["REQUEST_METHOD"] == 'POST') {
と使って順調ですねーと思ったら、単体テストのphpunitで動かない
「Notice: Undefined variable:」
と怒られちゃいました。

何故に!と思ってググってみたのですが解決方法が見つからず、どうしたもんかと思っていたら、公式にちゃっかり載ってました。
リクエストとレスポンスオブジェクト

確かに
if ($this->request->env('REQUEST_METHOD') == 'POST')
と書いたところ、phpunitでも上手く実行されたのですが、分かりづらいですよ公式さん。

いっそ、$_SERVERを使わず$this->request->envを使えと言って欲しかった・・

0
1
2

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
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?