PHP 8.4.26 Released!

Yaf_Registry::set

(Yaf >=1.0.0)

Yaf_Registry::set — 向注册表添加条目

说明

public static function Yaf_Registry::set(string $name, mixed $value): bool

向注册表中存储一个值。设置一个已经存在的名称会覆盖它之前的值。

参数

name

注册表条目的名称。

value

要存储的值;可以是任意类型,包括对象。

返回值

成功时返回 true,失败时返回 false。

示例

示例 #1 Yaf_Registry::set() 示例

<?php
class Bootstrap extends Yaf_Bootstrap_Abstract
{
    public function _initRedis(Yaf_Dispatcher $dispatcher)
    {
        $config = Yaf_Application::app()->getConfig()->redis;

        $redis = new Redis();
        $redis->connect($config->host, $config->port);

        /* 现在,该连接对整个应用可用 */
        Yaf_Registry::set("redis", $redis);
    }
}
?>

参见

+添加备注

用户贡献的备注

此页面尚无用户贡献的备注。
To Top