Zf framework registry (registry) example _ PHP Tutorial-php Tutorial

Source: Internet
Author: User
The registry usage example of the zf framework. The code for simply copying the code is as follows :? Phprequire_once (ZendLoader. php); Zend_Loader: loadClass (Zend_Registry); $ Arrarray (host127.0.0.1, usernameroot, pa simple to use

The code is as follows:


Require_once ("Zend/Loader. php ");
Zend_Loader: loadClass ("Zend_Registry ");
$ Arr = array
(
'Host' => '2017. 0.0.1 ',
'Username' => 'root ',
'Password' => '123 ',
'Dbname' => 'test'
);
$ Reg = new Zend_Registry ($ Arr );
Echo 'host name: '. $ Reg ['host']."
";
Echo 'user name: '. $ Reg ['username']."
";
Echo 'password: '. $ Reg ['password']."
";
Echo 'database: '. $ Reg ['dbname']."
";
Echo "";
Zend_Registry: set ('Table name', 'sanguo '); // SET value assignment method, which can also be assigned as an array
Echo Zend_Registry: get ('Table name'); // GET value method
?>

Object usage and set and get

The code is as follows:


// Introduce the Loader automatic loading class
Require_once ("Zend/Loader. php ");
// Load the registry object class
Zend_Loader: loadClass ("Zend_Registry ");
/*--------------------------------------------------------*/
// Perform registry operations as an object
// Instantiate the resources of the registry object class to $ Reg
$ Reg = new Zend_Registry ();
// Convert $ Reg to object format
Zend_Registry: setInstance ($ Reg );
// Assign a value to $ Reg (Registry)
$ Reg-> name = 'Zhang San ';
$ Reg-> sex = 'male ';
$ Reg-> age = '18 ';
// Obtain the static object and output it.
$ Reg = Zend_Registry: getInstance ();
Echo "name:". $ Reg-> name ."
";
Echo "gender:". $ Reg-> sex ."
";
Echo "age:". $ Reg-> age ."
";
/*--------------------------------------------------------*/
$ Arr = array ('name' => 'Zhang San', 'age' => '18', 'Hobbies '=> 'Surfing the 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 hobby is:". Zend_Registry: get ('my') ['Hobbies ']."
";
}
}
$ Person = new Person ();
$ Person-> My ();
?>

The pipeline code is as follows :? Php require_once ("Zend/Loader. php "); Zend_Loader: loadClass (" Zend_Registry "); $ Arr = array ('host' = '2017. 0.0.1 ', 'username' = 'root', 'Pa...

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.