Registry (registry) using the ZF Framework example _php instance

Source: Internet
Author: User
Tags zend

Simple to use

Copy Code code as follows:

<?php
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 ' Host name: '. $Reg [' Host ']. "<br>";
Echo ' username: '. $Reg [' username ']. "<br>";
echo ' Password: '. $Reg [' Password ']. "<br>";
echo ' Database: '. $Reg [' dbname ']. "<br>";
echo "Zend_registry::set (' Table name ', ' Sanguo '); Set assignment method, or you can assign an array of values
echo zend_registry::get (' table name '); Get method of fetching value
?>

object is used with the set, Get methods

Copy Code code as follows:

<?php
Introducing loader to automatically load classes
Require_once ("zend/loader.php");
Load Registry Object class
Zend_loader::loadclass ("Zend_registry");
/*--------------------------------------------------------*/
To perform a registry operation in the form of an object
Instantiate the resource assigned to the Registry object class to $reg
$Reg = new Zend_registry ();
Speak $reg convert to object format
Zend_registry::setinstance ($REG);
Assigning values to $reg (registry assignment)
$Reg->name = ' John ';
$Reg->sex = ' male ';
$Reg->age = ' 18 ';
Gets the static object after the output.
$Reg = Zend_registry::getinstance ();
echo "Name is:". $Reg->name. "<br>";
echo "Sex is:". $Reg->sex. "<br>";
echo "Age:". $Reg->age. "<br>";
/*--------------------------------------------------------*/
$ARR = Array (' name ' => ' John ', ' age ' => ' 18 ', ' Hobby ' => ' internet ');
Zend_registry::set (' my ', $ARR);
Class Person
{
Public function I ()
{
echo "My name is:". Zend_registry::get (' my ') [' name ']. "<br>";
echo "My Age is:". Zend_registry::get (' my ') [' age ']. "<br>";
echo "My hobby is:". Zend_registry::get (' my ') [' Hobby ']. "<br>";
}
}
$Person = new Person ();
$Person-> my ();
?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.