国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Home php教程 PHP開(kāi)發(fā) Zend Framework introductory tutorial: Detailed explanation of the usage of Zend_Registry component

Zend Framework introductory tutorial: Detailed explanation of the usage of Zend_Registry component

Jan 05, 2017 am 10:28 AM

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

Startup case:

<?php
require_once("Zend/Loader.php");
Zend_Loader::loadClass(&#39;Zend_Registry&#39;);
$member = array(
  "姓名"=>"張三",
  "性別"=>"女",
  "年齡"=>"13",
  "職業(yè)"=>"學(xué)生",
  "愛(ài)好"=>"玩游戲",
  "血型"=>"AB"
  );
$registry = new Zend_Registry($member);
echo "姓名為:";
echo $registry["姓名"];
echo "<p>";
echo "性別為:";
echo $registry["性別"];
echo "<p>";
echo "年齡為:";
echo $registry["年齡"];
echo "<p>";
echo "職業(yè)為:";
echo $registry["職業(yè)"];
echo "<p>";
echo "愛(ài)好為:";
echo $registry["愛(ài)好"];
echo "<p>";

Result For:

姓名為:張三
性別為:女
年齡為:13
職業(yè)為:學(xué)生
愛(ài)好為:玩游戲

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')

Case:

<?php
require_once("Zend/Loader.php");
Zend_Loader::loadClass(&#39;Zend_Registry&#39;);
$member = array(
  "姓名"=>"張三",
  "性別"=>"女",
  "年齡"=>"13",
  "職業(yè)"=>"學(xué)生",
  "愛(ài)好"=>"玩游戲",
  "血型"=>"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 "職業(yè)為:";
echo $registry["職業(yè)"];
echo "<p>";
echo "愛(ài)好為:";
echo $registry["愛(ài)好"];
echo "<p>";

Explanation: The effect is equivalent to the result of new.

3. Object registry setInstance, getInstance

Example:

<?php
require_once("Zend/Loader.php");
Zend_Loader::loadClass(&#39;Zend_Registry&#39;);
$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;

Result:

Mike
30
male

Explanation: Through the setInstance method, you can set the value in the form of an object, and then obtain the value through getInstance.

4.isRegistered() to determine whether the index has a value.

Case:

<?php
require_once("Zend/Loader.php");
Zend_Loader::loadClass(&#39;Zend_Registry&#39;);
Zend_Registry::set("name","張三");
if(Zend_Registry::isRegistered("name")){
  echo "對(duì)象注冊(cè)表name已經(jīng)定義";
}else{
  echo "對(duì)象注冊(cè)表name沒(méi)有定義";
}
echo "<p>";
if(Zend_Registry::isRegistered("age")){
  echo "對(duì)象注冊(cè)表age已經(jīng)定義";
}else{
  echo "對(duì)象注冊(cè)表age沒(méi)有定義";
}

Result:

對(duì)象注冊(cè)表name已經(jīng)定義
對(duì)象注冊(cè)表age沒(méi)有定義

Description:

If defined, it can be detected.

5. Delete the static registry

Zend_Registry::_unsetInstance() method deletes the static registry

Case:

<?php
require_once("Zend/Loader.php");
Zend_Loader::loadClass(&#39;Zend_Registry&#39;);
Zend_Registry::set("name","張三");
echo "執(zhí)行操作前:";
echo "<p>";
if(Zend_Registry::isRegistered("name")){
  echo "對(duì)象注冊(cè)表name已經(jīng)定義";
}else{
  echo "對(duì)象注冊(cè)表name沒(méi)有定義";
}
echo "<p>";
if(Zend_Registry::isRegistered("age")){
  echo "對(duì)象注冊(cè)表age已經(jīng)定義";
}else{
  echo "對(duì)象注冊(cè)表age沒(méi)有定義";
}
Zend_Registry::_unsetInstance("name");
echo "<p>";
echo "執(zhí)行操作后:";
echo "<p>";
if(Zend_Registry::isRegistered("name")){
  echo "對(duì)象注冊(cè)表name已經(jīng)定義";
}else{
  echo "對(duì)象注冊(cè)表name沒(méi)有定義";
}
echo "<p>";
if(Zend_Registry::isRegistered("age")){
  echo "對(duì)象注冊(cè)表age已經(jīng)定義";
}else{
  echo "對(duì)象注冊(cè)表age沒(méi)有定義";
}

Result:

執(zhí)行操作前:
對(duì)象注冊(cè)表name已經(jīng)定義
對(duì)象注冊(cè)表age沒(méi)有定義
執(zhí)行操作后:
對(duì)象注冊(cè)表name沒(méi)有定義
對(duì)象注冊(cè)表age沒(méi)有定義

Explanation: After executing the deletion method, the previous registration information will be gone.

Summary:

These are several commonly used methods and cases of Zend_Registry. Many functions that cannot be achieved with ordinary variables can be achieved through the registry.

I hope this article will be helpful to everyone’s PHP programming based on the Zend Framework framework.

For more detailed explanations on the usage of the Zend_Registry component in the Zend Framework introductory tutorial, please pay attention to the PHP Chinese website!

Statement of this Website
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

Undress AI Tool

Undress AI Tool

Undress images for free

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.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)