This example describes the usage of Zend_registry components in the Zend Framework. Share to everyone for your reference, specific as follows:
1. Object Registration Form
Getting Started case:
<?php
require_once ("zend/loader.php");
Zend_loader::loadclass (' zend_registry ');
$member = Array (
"name" => "John", "
gender" => "female",
"age" => "," "
occupation" => "student",
"hobby" => "Play games",
"Blood type" => "AB"
);
$registry = new Zend_registry ($member);
echo "name is:";
echo $registry ["name"];
echo "<p>";
echo "Sex is:";
echo $registry ["gender"];
echo "<p>";
echo "Age is:";
echo $registry ["age"];
echo "<p>";
echo "Occupation for:";
echo $registry ["occupation"];
echo "<p>";
echo "Hobby for:";
echo $registry ["hobby"];
echo "<p>";
The results are:
The name is: John
sex is: The female
age is: The occupation is: the
student
hobby is: plays the game
2.set () method and get () method to set data, fetch data
Grammar:
Set value Zend_registry::set (' Index ', ' value ')
Get value Zend_registry::get (' index ')
Case:
<?php
require_once ("zend/loader.php");
Zend_loader::loadclass (' zend_registry ');
$member = Array (
"name" => "John", "
gender" => "female",
"age" => "," "
occupation" => "student",
"hobby" => "Play games",
"Blood type" => "AB"
);
Zend_registry::set ("Registry", $member);
$registry = Zend_registry::get ("registry");
echo "name is:";
echo $registry ["name"];
echo "<p>";
echo "Sex is:";
echo $registry ["gender"];
echo "<p>";
echo "Age is:";
echo $registry ["age"];
echo "<p>";
echo "Occupation for:";
echo $registry ["occupation"];
echo "<p>";
echo "Hobby for:";
echo $registry ["hobby"];
echo "<p>";
Description: The effect is equivalent to the result of new.
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 = "a";
$registry = Zend_registry::getinstance ();
echo $registry->name;
echo "<p>";
echo $registry->age;
echo "<p>";
$registry->sex = "male";
Echo $registry->sex;
Results:
Note: By using the Setinstance method, you can set the value in the object's way, and then getinstance to get the value.
4.isRegistered () to realize whether the index has a value of judgment.
Case:
<?php
require_once ("zend/loader.php");
Zend_loader::loadclass (' zend_registry ');
Zend_registry::set ("name", "John");
if (zend_registry::isregistered ("name")) {
Echo Object Registry name is already defined;
} else{
echo "Object registry name is not defined";
}
echo "<p>";
if (zend_registry::isregistered ("Age")) {
Echo Object Registry age is already defined;
} else{
echo "Object Registry age is not defined";
}
Results:
Object Registry name already defined
Object Registry age not defined
Description
If it is defined, it can be detected.
5. Delete 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", "John");
echo "Before performing operation:";
echo "<p>";
if (zend_registry::isregistered ("name")) {
Echo Object Registry name is already defined;
} else{
echo "Object registry name is not defined";
}
echo "<p>";
if (zend_registry::isregistered ("Age")) {
Echo Object Registry age is already defined;
} else{
echo "Object Registry age is not defined";
}
Zend_registry::_unsetinstance ("name");
echo "<p>";
echo "After the operation:";
echo "<p>";
if (zend_registry::isregistered ("name")) {
Echo Object Registry name is already defined;
} else{
echo "Object registry name is not defined";
}
echo "<p>";
if (zend_registry::isregistered ("Age")) {
Echo Object Registry age is already defined;
} else{
echo "Object Registry age is not defined";
}
Results:
Before performing an action: Object registry
name has been defined
Object Registry age is not defined
after performing an action: Object registry
name does not define
object Registry age not defined
Note: After the deletion method is completed, the registration information is not.
Summary:
This is the zend_registry of several commonly used methods and cases. The registry allows you to implement functions that many ordinary variables cannot implement.
More interested in Zend related content readers can view the site topics: "The introduction of the Zend Framework frame", "PHP Excellent Development Framework Summary", "Yii framework Introduction and common skills Summary", "thinkphp Introductory Course", "PHP object-oriented Programming Program , "Php+mysql Database operation Introduction Tutorial" and "PHP common database Operation Skills Summary"
I hope this article will help you with the PHP program design based on the Zend Framework.