Home >Backend Development >PHP Tutorial >How to use ZF framework Registry (registry)

How to use ZF framework Registry (registry)

WBOY
WBOYOriginal
2016-07-25 08:48:351048browse
study homework
  1. require_once("Zend/Loader.php");
  2. Zend_Loader::loadClass("Zend_Registry");
  3. $Arr = array
  4. (
  5. 'host' => '127.0.0.1' ,
  6. 'username' => 'root',
  7. 'password' => '111',
  8. 'dbname' => 'test'
  9. );
  10. $Reg = new Zend_Registry($Arr);
  11. echo ' Hostname:' . $Reg['host'] . "
    ";
  12. echo 'Username:' . $Reg['username'] . "
    ";
  13. echo 'Password:' . $Reg['password'] . "
    ";
  14. echo 'Database:' . $Reg['dbname'] . "
    ";
  15. echo "
    ";
  16. Zend_Registry:: set('table name','sanguo'); //SET assignment method, you can also assign the value to an array
  17. echo Zend_Registry::get('table name'); //GET value method
  18. ?>
Copy Code
  1. //Introducing Loader to automatically load classes
  2. require_once("Zend/Loader.php");
  3. //Loading registry object classes
  4. Zend_Loader::loadClass("Zend_Registry");
  5. /*------------------------------------------------ --------*/
  6. //Perform registry operations in object mode
  7. //Assign the resources of the instantiated registry object class to $Reg
  8. $Reg = new Zend_Registry();
  9. //Talk about $Reg Convert to object format
  10. Zend_Registry::setInstance($Reg);
  11. //Assign value to $Reg (registry assignment)
  12. $Reg ->name = 'Zhang San';
  13. $Reg ->sex = 'Male ';
  14. $Reg ->age = '18';
  15. //Output after obtaining the static object.
  16. $Reg = Zend_Registry::getInstance();
  17. echo "The name is: " . $Reg->name . "
    ";
  18. echo "Gender is:" . $Reg->sex . "
    ";
  19. echo "Age is:" . $Reg->age . "
    ";
  20. /*-------------------------------------------------- ---------*/
  21. $Arr = array('Name' => 'Zhang San','Age' => '18','Hobby' => 'Internet');
  22. Zend_Registry::set('My',$Arr);
  23. class Person
  24. {
  25. public function My()
  26. {
  27. echo "My name is:" . Zend_Registry::get('My')['Name'] . "
    ";
  28. echo "My age is:" . Zend_Registry::get('My')['Age'] . "
    ";
  29. echo "My hobbies are:" . Zend_Registry::get('My')['Hobby'] . "
    ";
  30. }
  31. }
  32. $Person = new Person();
  33. $Person -> My();
  34. ?>
Copy code


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