Welcome, Guest. Register Now!
   
Mark Forums Read Mark Forums Read Mark Forums Read


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-20-2008, 08:21 PM
Junior Member
 
Join Date: Jun 2008
Posts: 4
Unhappy ZF n00b - lost in session namespaces

Where do I place the namespace initialization to make a specific namespace available to all aspects of a project (layout files, controllers and views)?

if I place the following code in the bootstrap file, I can access it there, but not anywhere else:

$authNamespace = new Zend_Session_Namespace('authNamespace');
echo $authNamespace->fName;
echo $authNamespace->lName;

I tried setting it in the init() section of the controller I was in, using:
$this->authNamespace = new Zend_Session_Namespace('authNamespace');

What am I missing here?

Before anyone harps on me for not using Zend_Auth, the user details are pulled from a separate database after the user is logged in, as login credentials are coming from an LDAP server and user details are coming from a separate MS SQL server.

Thanks in advance for any insight

-=Tricky=-
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 06-20-2008, 08:29 PM
Junior Member
 
Join Date: Jun 2008
Posts: 4
Default

HA

I just discovered Zend_Registry - I'll see if this helps me out
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 06-20-2008, 08:32 PM
Member
 
Join Date: Jun 2008
Location: Florida
Posts: 94
Default

The scope of the namespace as you are creating it is the same as any other variable. If you want to make the namespace available elsewhere you need to instantiate the Zend_Session_Namespace class everywhere that you want it available, or store it in a variable whose scope is accessible to each class/script that you want to have access to it.

For exmaple, you could place it in a view variable one time in your controller:
Code:
$this->view->exampleNamespace = new Zend_Session_Namespace('example');

$this->view->exampleNamespace = 'hello world';
Then throughout your controller calling this:
Code:
echo $this->view->exampleNamespace;
Will result in:
Code:
hello world
To access this same variable in your view you simply refer to it as $this->exampleNamespace.

If you wanted to narrow the scope a bit you could create a private class variable in your controller. Then any method in that controller class would of course have access to any value in that variable.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 06-20-2008, 08:41 PM
Junior Member
 
Join Date: Jun 2008
Posts: 4
Default

See, this is what confuses the hell out of me.

From everything I've knkown of PHP, when creating a session variable (isn't that what namespaces are?), that variable should be available on any script until the user logs out, times out their session, or closes their browser. However, everything I've read on namespaces and Zend_Session only show vars being available in the script that they're generated in.

I am looking for these values to be available to all scripts at all times. I am looking at Zend_Registry - this sounds more like traditional PHP Sessions than anything else I've found.

Please give me some direction because currently, Zend Framework is *really* making me want to go back to the application codebase I already have built.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 06-20-2008, 08:48 PM
Junior Member
 
Join Date: Jun 2008
Posts: 4
Default

Also, how is any of this easier than just using $_SESSION['user']['fName'] = $value ?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 06-20-2008, 08:48 PM
Member
 
Join Date: Jun 2008
Location: Florida
Posts: 94
Default

The variable that holds the results of instantiating Zend_Session_Namespace is a Zend_Session_Namespace object. This variable respects the scope rules of any other variable. Part of instantiating this class is that it stores a value in the php $_SESSION array. So, for example, if you did:

Code:
$exampleNamespace = new Zend_Session_Namespace('example');
$exampleNamespace->fname = 'jweber';
You could get to that "jweber" by echoing out the class member "fname", or you could get to it by echoing out its corresponding key in the $_SESSION array, which in this case is $_SESSION['example']['fname']. $_SESSION['example']['fname'] has global scope while $exampleNamespace->fname has the scope associated with the variable $exampleNamespace. From what I recall of the ZF manual, they are discouraging accessing this value by directly interacting with the $_SESSION array.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 06-20-2008, 08:51 PM
Member
 
Join Date: Jun 2008
Location: Florida
Posts: 94
Default

The intro section of the manual on Zend_Session covers what Zend_Session does, and the logic behind using it:
Zend Framework: Documentation
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 01:14 AM.