search
Homephp教程php手册zf框架的registry(注册表)使用示例

简单使用

复制代码 代码如下:


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'] . "
";
echo '用户名:' . $Reg['username'] . "
";
echo '密码:' . $Reg['password'] . "
";
echo '数据库:' . $Reg['dbname'] . "
";
echo "


";
Zend_Registry::set('表名','sanguo');  //SET赋值方法,也可以赋值为数组
echo Zend_Registry::get('表名');  //GET取值方法
?>

对象方式使用与set、get方法使用

复制代码 代码如下:


//引入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 . "
";
echo "性别为:" . $Reg->sex . "
";
echo "年龄为:" . $Reg->age . "
";
/*--------------------------------------------------------*/
$Arr = array('姓名' => '张三','年龄' => '18','爱好' => '上网');
Zend_Registry::set('My',$Arr);
class Person
{
 public function My()
 {
  echo "我的姓名是:" . Zend_Registry::get('My')['姓名'] . "
";
  echo "我的年龄是:" . Zend_Registry::get('My')['年龄'] . "
";
  echo "我的爱好是:" . Zend_Registry::get('My')['爱好'] . "
";
 }
}
$Person = new Person();
$Person -> My();
?>

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.