php8.5
Home/ Manual/ yaf / yaf_registry/ Yaf_Registry::get

Yaf_Registry::get

PHP function Edit on GitHub ✎

(Yaf >=1.0.0)

Retrieve an item from registry

Description

Yaf_Registry::get(string $name): mixed

Retrieves a value from the registry.

Parameters

name

The name of the registry entry.

Return Values

The value stored under name, or null if there is no entry with that name.

Examples

Yaf_Registry::get example

php
<?php
class IndexController extends Yaf_Controller_Abstract
{
    public function indexAction()
    {
        $redis = Yaf_Registry::get("redis");
        if ($redis === null) {
            throw new Exception("the redis connection is not registered");
        }

        $this->getView()->assign("visits", $redis->get("site:visits"));

        return true;
    }
}
?>

See Also

  • Yaf_Registry::set
  • Yaf_Registry::has
  • Yaf_Registry::del

Source: reference/yaf/yaf_registry/get.xml · from the official PHP manual (php/doc-en)