01 Dec
Posted by Ganesh H S , Bangalore, India as zend framework
In php programming we always used global or $_GLOBALS to refer to the global variable.
For example consider below -
Db.php
<?php
// connect to mysql server
$mysqlLink = mysql_connect("mysql_server", "mysql_user", "mysql_password");
?>
index.php
<?php
require_once "Db.php";
function displayTables()
{
global $mysqlLink;
$sql = "SHOW TABLES";
//use global variable mysqlLink, and perform query execution
mysql_query($sql, $mysqlLink);
?>
<?php
require_once "Zend/Session.php";
require_once "Zend/Session/Namespace.php";
Zend_Session::start();
$consumer = new Zend_Session_Namespace("consumer");
Zend_Registry::set(’consumer’, $consumer);
$consumer->name = "Ganesh";
?>
In this example, we will retrieve the session value, using zend registry.
<?php
echo "Consumer name:" . Zend_Registry::get('consumer')->name;
?>
| M | T | W | T | F | S | S |
|---|---|---|---|---|---|---|
| « Jul | ||||||
| 1 | 2 | |||||
| 3 | 4 | 5 | 6 | 7 | 8 | 9 |
| 10 | 11 | 12 | 13 | 14 | 15 | 16 |
| 17 | 18 | 19 | 20 | 21 | 22 | 23 |
| 24 | 25 | 26 | 27 | 28 | 29 | 30 |
RSS feed for comments on this post · TrackBack URI
Leave a reply