Home >Backend Development >PHP Tutorial >Example of using registry (registry) of zf framework_PHP tutorial

Example of using registry (registry) of zf framework_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:35:59860browse

Easy to use

Copy code The code is as follows:

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 'Hostname:' . $Reg['host'] . "
";
echo 'Username:' . $Reg['username'] . "
";
echo 'Password:' . $Reg['password'] . "
";
echo 'Database:' . $Reg['dbname'] . "
";
echo "
";
Zend_Registry::set('table name','sanguo'); //SET assignment method, you can also assign the value to an array
echo Zend_Registry::get('table name '); //GET value method
?>

Using object mode and using set and get methods

Copy code The code is as follows:

>//Introducing Loader to automatically load the class
require_once("Zend/Loader.php");
//Loading the registry object class
Zend_Loader::loadClass("Zend_Registry");
/*------------------------------------------------ --------*/
//Perform registry operations in object mode
//Assign the resources of the instantiated registry object class to $Reg
$Reg = new Zend_Registry();
//Convert $Reg to object format
Zend_Registry::setInstance($Reg);
//Assign value to $Reg (registry assignment)
$Reg ->name = ' Zhang San';
$Reg ->sex = 'Male';
$Reg ->age = '18';
//Output after obtaining the static object.
$Reg = Zend_Registry ::getInstance();
echo "Name is:" . $Reg->name . "
";
echo "Gender is: " . $Reg->sex . "< br>";
echo "Age is:" . $Reg->age . "
";
/*----------------- ---------------------------------------*/
$Arr = array(' Name' => 'Zhang San','Age' => '18','Hobby' => 'Internet');
Zend_Registry::set('My',$Arr);
class Person
{
public function My()
{
echo "My name is:" . Zend_Registry::get('My')['Name'] . "
";
echo "My age is:" . Zend_Registry::get('My')['Age'] . "
";
echo "My hobbies are:" . Zend_Registry: :get('My')['Hobby'] . "
";
}
}
$Person = new Person();
$Person -> My() ;
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/741264.htmlTechArticleSimple copy code is as follows: ?php require_once("Zend/Loader.php"); Zend_Loader::loadClass ("Zend_Registry"); $Arr = array ( 'host' = '127.0.0.1', 'username' = 'root', 'pa...
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