PHP 8.6.0 Beta 2 available for testing

Yaf_Request_Abstract::getQuery

(Yaf >=3.2.2)

Yaf_Request_Abstract::getQueryFetch a query parameter

説明

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

Retrieves a variable from $_GET.

パラメータ

name

The variable name. If omitted, the whole array is returned.

default

The value to return if the variable is not found.

戻り値

The query parameter value, or default if it is not set.

例1 Yaf_Request_Abstract::getQuery() example

<?php
class SearchController extends Yaf_Controller_Abstract
{
    public function indexAction()
    {
        // Assuming the request is /search?keyword=yaf&page=2
        $keyword = $this->getRequest()->getQuery("keyword");
        $page    = (int) $this->getRequest()->getQuery("page", 1);

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

上の例の出力は、 たとえば以下のようになります。

string(3) "yaf"
int(2)

参考

add a note

User Contributed Notes

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