Application::in
リクエストのデータ(POST/GET)を取得します
説明
public string|array Application::in( string $name = '', string $method = '' )
$_GETと$_POSTからリクエストのデータを取得します。
$nameを指定すると、そのパラメーターの値を返します(文字列。ids[]のようなパラメーターでは配列)。パラメーターがないか空文字列のときは''を返します。$nameを省略すると、すべてのパラメーターを配列で返します(パラメーターが1つもなければ'')。- GETとPOSTに同じ名前のパラメーターがあるときは、POSTを優先します。
値は送られたまま返し、エスケープはしません。使う前にバリデーションをし、データベースには?のプレースホルダーでだけ渡し、出力時のエスケープはテンプレートに任せてください。
引数
| 名前 | データ型 | デフォルト | 備考 |
|---|---|---|---|
| $name | string | '' | リクエストパラメーターの名前。省略するとすべてのパラメーター |
| $method | string | '' | どちらか一方だけを読むときは'get'か'post'(大文字と小文字は区別しません)。省略すると両方 |
例
Controller - GET
// https://example.com/?foo=get
echo $this->in('foo'); // -> get
echo $this->in('foo', 'get'); // -> get
echo $this->in('foo', 'post'); // -> '' (empty string)
Controller - POST
// https://example.com/ : POST('foo' => 'post')
echo $this->in('foo'); // -> post
echo $this->in('foo', 'get'); // -> ''
echo $this->in('foo', 'post'); // -> post
Controller - GET and POST
// https://example.com/?foo=get : POST('foo' => 'post')
echo $this->in('foo'); // -> post
echo $this->in('foo', 'get'); // -> get
echo $this->in('foo', 'post'); // -> post
最初の引数を省略した場合です。
Controller
// https://example.com/ : POST('foo' => 'bar', 'baz' => 'qux')
var_dump( $this->in() );
Output
array(2) { ["foo"]=> string(3) "bar" ["baz"]=> string(3) "qux" }
よくある使い方は、一覧のページ番号です。
htdocs/_fegg/site/src/Controller/News.php
$this->page['data'] = $this->_model
->listMax(20)
->current($this->in('p'))
->order('post_date', 'desc')
->find();