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...