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"

Прогляньте також

add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top