メインコンテンツまでスキップ
Version: Fegg 5.x(開発版)

Application::in

Get request data (POST/GET)

Description​

public string|array Application::in( string $name = '', string $method = '' )

Get request data from $_GET and $_POST.

  • With $name, returns the value of that parameter (a string, or an array for parameters like ids[]). If the parameter is missing or an empty string, returns ''.
  • Without $name, returns all parameters as an array ('' when there are none).
  • If GET and POST have a parameter with the same name, POST wins.

The value is returned as it was sent. It is not escaped: validate it before use, pass it to the database only through ? placeholders, and let the template escape it on output.

Arguments​

NameData typeDefaultRemarks
$namestring''Request parameter name. All parameters when omitted
$methodstring'''get' or 'post' (case-insensitive) to read only one of them. Both when omitted

Example​

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

If POST and GET have a parameter with the same name, POST wins.

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

You can get all request data by omitting the first argument.

Controller
// https://example.com/ : POST('foo' => 'bar', 'baz' => 'qux')

var_dump( $this->in() );
Output
array(2) { ["foo"]=> string(3) "bar" ["baz"]=> string(3) "qux" }

A typical use is the page number of a list:

htdocs/_fegg/site/controller/News.php
$this->page['data'] = $this->_model
->listMax(20)
->current($this->in('p'))
->order('post_date', 'desc')
->find();