PHP 8.6.0 Beta 2 available for testing

Yaf_Request_Abstract::get

(Yaf >=3.2.2)

Yaf_Request_Abstract::getRetrieve a variable from the request

Описание

public function Yaf_Request_Abstract::get(string $name, mixed $default = ?): mixed

Retrieves a variable from the request. The search order is: request parameters set by Yaf_Request_Abstract::setParam(), then POST, GET, COOKIE, SERVER.

Список параметров

name

The variable name.

default

The value to return if the variable is not found.

Возвращаемые значения

The value if found, or default if it was provided, null otherwise.

Примеры

Пример #1 Yaf_Request_Abstract::get() example

<?php
class SearchController extends Yaf_Controller_Abstract
{
    public function indexAction()
    {
        $request = $this->getRequest();

        // Assuming the request is /search?keyword=yaf&page=2
        $keyword = $request->get("keyword");
        $page    = (int) $request->get("page", 1);
        $sort    = $request->get("sort", "relevance");

        var_dump($keyword, $page, $sort);
    }
}
?>

Вывод приведённого примера будет похож на:

string(3) "yaf"
int(2)
string(9) "relevance"

Смотрите также

Добавить

Примечания пользователей

Пользователи ещё не добавляли примечания для страницы
To Top