zf框架的registry(注册表)使用示例
程序员文章站
2022-07-20 13:24:51
简单使用复制代码 代码如下:
<?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取值方法
?>
<?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();
?>
简单使用
复制代码 代码如下:
<?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();
?>
上一篇: 拌香菜的做法
下一篇: JavaScript实现无穷滚动加载数据