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;
?>
5 Responses
subrmanian
December 10th, 2008 at 2:02 am
1good your example is quite simple and easy to understand
Naveen kuar
February 20th, 2009 at 4:22 am
2Hi ganesh,
First of all am new to zend framework and am presently having some problems in understanding the zend framework and how it behaves.
two of them with high priority are
1) am trying to set an object (ex: $db) in the zend_registry (zend_registry::set(’db’,$db)) and trying to get it back. This is working fine if I am setting it in bootstrap and getting it in any controller action. But when am trying to set it in one controller (ex: indexController) and get it in another controller (ex: myController). this is not working fine.
if the value which i set is a string.. then its working fine in cross-controller example but when it is an object its not working. Rakesh (your friend who is my coleague) told me that you are a Jem in zend. I am struck with my work bcos of this issue. pls help me ..
2) second one is when am trying to provide a download from one of my actions (a pdf file).. the file is getting downloaded but the file when am opening it, its displaying an error something like ” corrupted , was not decoded properly”. The actual pdf file am opening in the same acrobat reader and its opening. can you give me any suggestions in this case.
Thanks in advance..
Naveen
Ganesh H S , Bangalore, India
February 22nd, 2009 at 1:58 pm
31. Lets take this offline, contact me on me at ganeshhs dot com
2. Never worked on zend and pdf, let me see how i can help you.
rate pics
March 17th, 2009 at 12:09 pm
4For me.. In order for me to use Zend_Registry I MUST require once “Zend/Registry” in bootstrap.
Ganesh H S , Bangalore, India
March 17th, 2009 at 8:23 pm
5The above example is isolated example, in projects i always use Zend_Registry in bootstrap file, and i register the db object, conf object in Zend_Registry
RSS feed for comments on this post · TrackBack URI
Leave a reply
Categories
Archives
Blogroll
Recent Comments
Ganesh H S is proudly powered by WordPress - BloggingPro theme by: Design Disease