This article mainly introduces the usage of the Zend_Registry component in the Zend Framework introductory tutorial, and analyzes the common techniques of Zend_Registry component to implement object registration settings, acquisition, judgment, deletion and other operations in the form of examples. Friends in need can refer to it
The example in this article describes the usage of Zend_Registry component in Zend Framework. Share it with everyone for your reference, the details are as follows:
1. Object Registry
Getting Started Case:
<?php require_once("Zend/Loader.php"); Zend_Loader::loadClass('Zend_Registry'); $member = array( "姓名"=>"张三", "性别"=>"女", "年龄"=>"13", "职业"=>"学生", "爱好"=>"玩游戏", "血型"=>"AB" ); $registry = new Zend_Registry($member); echo "姓名为:"; echo $registry["姓名"]; echo "<p>"; echo "性别为:"; echo $registry["性别"]; echo "<p>"; echo "年龄为:"; echo $registry["年龄"]; echo "<p>"; echo "职业为:"; echo $registry["职业"]; echo "<p>"; echo "爱好为:"; echo $registry["爱好"]; echo "<p>";
The result is:
姓名为:张三 性别为:女 年龄为:13 职业为:学生 爱好为:玩游戏
##2.set() method and get() method to set data and get data
Syntax:Set the value Zend_Registry::set('index','value')Get the value Zend_Registry::get('index')
<?php require_once("Zend/Loader.php"); Zend_Loader::loadClass('Zend_Registry'); $member = array( "姓名"=>"张三", "性别"=>"女", "年龄"=>"13", "职业"=>"学生", "爱好"=>"玩游戏", "血型"=>"AB" ); Zend_Registry::set("registry",$member); $registry = Zend_Registry::get("registry"); echo "姓名为:"; echo $registry["姓名"]; echo "<p>"; echo "性别为:"; echo $registry["性别"]; echo "<p>"; echo "年龄为:"; echo $registry["年龄"]; echo "<p>"; echo "职业为:"; echo $registry["职业"]; echo "<p>"; echo "爱好为:"; echo $registry["爱好"]; echo "<p>";
3. Object registry setInstance, getInstance
Example:<?php require_once("Zend/Loader.php"); Zend_Loader::loadClass('Zend_Registry'); $registry = new Zend_Registry(); Zend_Registry::setInstance($registry); $registry->name = "Mike"; $registry->age = "30"; $registry = Zend_Registry::getInstance(); echo $registry->name; echo "<p>"; echo $registry->age; echo "<p>"; $registry->sex = "male"; echo $registry->sex;
Mike 30 male
4.isRegistered() to determine whether the index has a value.
Case:<?php require_once("Zend/Loader.php"); Zend_Loader::loadClass('Zend_Registry'); Zend_Registry::set("name","张三"); if(Zend_Registry::isRegistered("name")){ echo "对象注册表name已经定义"; }else{ echo "对象注册表name没有定义"; } echo "<p>"; if(Zend_Registry::isRegistered("age")){ echo "对象注册表age已经定义"; }else{ echo "对象注册表age没有定义"; }
对象注册表name已经定义 对象注册表age没有定义
5. Delete the static registry
Zend_Registry::_unsetInstance() method deletes the static registry Case:<?php require_once("Zend/Loader.php"); Zend_Loader::loadClass('Zend_Registry'); Zend_Registry::set("name","张三"); echo "执行操作前:"; echo "<p>"; if(Zend_Registry::isRegistered("name")){ echo "对象注册表name已经定义"; }else{ echo "对象注册表name没有定义"; } echo "<p>"; if(Zend_Registry::isRegistered("age")){ echo "对象注册表age已经定义"; }else{ echo "对象注册表age没有定义"; } Zend_Registry::_unsetInstance("name"); echo "<p>"; echo "执行操作后:"; echo "<p>"; if(Zend_Registry::isRegistered("name")){ echo "对象注册表name已经定义"; }else{ echo "对象注册表name没有定义"; } echo "<p>"; if(Zend_Registry::isRegistered("age")){ echo "对象注册表age已经定义"; }else{ echo "对象注册表age没有定义"; }
执行操作前: 对象注册表name已经定义 对象注册表age没有定义 执行操作后: 对象注册表name没有定义 对象注册表age没有定义
About Zend Framework’s method of processing Json data
About the usage of Loader and PluginLoader in Zend Framework Analysis
About the usage of Zend Framework action controller
##
The above is the detailed content of Usage analysis of Zend_Registry component in Zend Framework. For more information, please follow other related articles on the PHP Chinese website!