Yaf_Request_Abstract::getCookie
PHP Manual
PHP Manual»Yaf_Request_Abstract»Yaf_Request_Abstract::getCookie

Yaf_Request_Abstract::getCookie

(Yaf >=3.2.2)

Yaf_Request_Abstract::getCookie — Fetch a COOKIE variable

説明

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

Retrieves a variable from $_COOKIE.

パラメータ

name

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

default

The value to return if the variable is not found.

戻り値

The cookie value, or default if it is not set.

例

例1 Yaf_Request_Abstract::getCookie() example

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

        $theme     = $request->getCookie("theme", "light");
        $sessionId = $request->getCookie("sid");

        var_dump($theme, $sessionId);
    }
}
?>

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

string(4) "dark"
string(8) "1f2a3b4c"

参考

To Top