|
|||
|
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=- |
|
|||
|
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';
Code:
echo $this->view->exampleNamespace; Code:
hello world 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. |
|
|||
|
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. |
|
|||
|
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';
|
|
|||
|
The intro section of the manual on Zend_Session covers what Zend_Session does, and the logic behind using it:
Zend Framework: Documentation |
![]() |
| Thread Tools | |
| Display Modes | |
|
|