How to use ZF framework Registry (registry)
Release: 2016-07-25 08:48:35
Original
1029 people have browsed it
study homework
- 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
- ?>
Copy Code
- //Introducing Loader to automatically load classes
- require_once("Zend/Loader.php");
- //Loading registry object classes
- 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();
- //Talk about $Reg Convert 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 "The name is: " . $Reg->name . "
";
- echo "Gender is:" . $Reg->sex . "
";
- 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();
- ?>
Copy code
|
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
Latest Articles by Author
-
2024-10-22 09:46:29
-
2024-10-13 13:53:41
-
2024-10-12 12:15:51
-
2024-10-11 22:47:31
-
2024-10-11 19:36:51
-
2024-10-11 15:50:41
-
2024-10-11 15:07:41
-
2024-10-11 14:21:21
-
2024-10-11 12:59:11
-
2024-10-11 12:17:31