(编辑:jimmy 日期: 2024/11/16 浏览:2)
简单使用
复制代码 代码如下:
<?php
require_once("Zend/Loader.php");
Zend_Loader::loadClass("Zend_Registry");
$Arr = array
(
'host' => '127.0.0.1',
'username' => 'root',
'password' => '111',
'dbname' => 'test'
);
$Reg = new Zend_Registry($Arr);
echo '主机名:' . $Reg['host'] . "<br>";
echo '用户名:' . $Reg['username'] . "<br>";
echo '密码:' . $Reg['password'] . "<br>";
echo '数据库:' . $Reg['dbname'] . "<br>";
echo "<hr>";
Zend_Registry::set('表名','sanguo'); //SET赋值方法,也可以赋值为数组
echo Zend_Registry::get('表名'); //GET取值方法
?>
对象方式使用与set、get方法使用
复制代码 代码如下:
<?php
//引入Loader自动载入类
require_once("Zend/Loader.php");
//载入注册表对象类
Zend_Loader::loadClass("Zend_Registry");
/*--------------------------------------------------------*/
//以对象方式进行注册表操作
//实例化注册表对象类的资源赋给$Reg
$Reg = new Zend_Registry();
//讲$Reg转换为对象格式
Zend_Registry::setInstance($Reg);
//对$Reg进行赋值(注册表赋值)
$Reg ->name = '张三';
$Reg ->sex = '男';
$Reg ->age = '18';
//获取静态对象后输出.
$Reg = Zend_Registry::getInstance();
echo "姓名为:" . $Reg->name . "<br>";
echo "性别为:" . $Reg->sex . "<br>";
echo "年龄为:" . $Reg->age . "<br>";
/*--------------------------------------------------------*/
$Arr = array('姓名' => '张三','年龄' => '18','爱好' => '上网');
Zend_Registry::set('My',$Arr);
class Person
{
public function My()
{
echo "我的姓名是:" . Zend_Registry::get('My')['姓名'] . "<br>";
echo "我的年龄是:" . Zend_Registry::get('My')['年龄'] . "<br>";
echo "我的爱好是:" . Zend_Registry::get('My')['爱好'] . "<br>";
}
}
$Person = new Person();
$Person -> My();
?>