phptek Posted November 23, 2011 Report Share Posted November 23, 2011 Can you please post an example of setting the username of the user into a session and displaying it on the page as a greeting as "Hello username". Can you please use an easy way to do it using the latest zend framework in controller class? Thanks a lot. Sam Quote Link to comment Share on other sites More sharing options...
falkencreative Posted November 23, 2011 Report Share Posted November 23, 2011 I can't tell you how to do it within Zend... but I can't see why you couldn't use regular PHP within Zend? session_start(); $_SESSION['username'] = 'username'; // set session echo $_SESSION['username']; // display username If Zend has it's own unique way of handling sessions though, this may not be helpful. In that case, hopefully another user can help you out. This might also help you: http://zendgeek.blogspot.com/2009/07/zend-framework-session-usage-and.html Quote Link to comment Share on other sites More sharing options...
phptek Posted November 23, 2011 Author Report Share Posted November 23, 2011 I can't tell you how to do it within Zend... but I can't see why you couldn't use regular PHP within Zend? session_start(); $_SESSION['username'] = 'username'; // set session echo $_SESSION['username']; // display username If Zend has it's own unique way of handling sessions though, this may not be helpful. In that case, hopefully another user can help you out. This might also help you: http://zendgeek.blogspot.com/2009/07/zend-framework-session-usage-and.html Thank you, Ben. I am familiar with regular php syntax. I was wondering if there are some classes from which i can use some methods to set sessions in Zend framework. I will check out the link you posted as well. BTW, the videos from killerphp are what got me into Zend, and now I'm loving it. Thanks for all you do to the community. Happy Thanksgiving. - Sam Quote Link to comment Share on other sites More sharing options...
jstern Posted November 23, 2011 Report Share Posted November 23, 2011 Set into Registry: Zend_Registry::set($index, $value); to retrieve that you've store: $session = Zend_Registry::get($index); //value is now stored into $session you can even store / pass an object and work on it if you have to: $session = Zend_Registry::get($index)->objectMethod(); Usually a good idea to check if your registry entry exists before tryig to access: if (Zend_Registry::isRegistered($index)) { ... } Quote Link to comment Share on other sites More sharing options...
jstern Posted November 23, 2011 Report Share Posted November 23, 2011 realized after i had some lunch that my post might have confused you since i used Zend_Registry examples Zend_Registry and Zend_Session_Namespace are different obviously. If you must use sessions then below are some examples as well. start or call your session $session = new Zend_Session_Namespace($name); add something to your session $session->index = $value; call that value somewhere else in your code $session = new Zend_Session_Namespace($name); //make sure its set if(!isset($session->index)){ //set it } else { //do what ya need to with its value } Registry will be cleared with every new Bootstrap request, thus you'd need to ensure your values are setup to load into it with every request, so it may not be useful with whatever you are planning to do. I tend to use them more often than Zend_Session_Namespace however. Quote Link to comment Share on other sites More sharing options...
phptek Posted November 26, 2011 Author Report Share Posted November 26, 2011 realized after i had some lunch that my post might have confused you since i used Zend_Registry examples Zend_Registry and Zend_Session_Namespace are different obviously. If you must use sessions then below are some examples as well. start or call your session $session = new Zend_Session_Namespace($name); add something to your session $session->index = $value; call that value somewhere else in your code $session = new Zend_Session_Namespace($name); //make sure its set if(!isset($session->index)){ //set it } else { //do what ya need to with its value } Registry will be cleared with every new Bootstrap request, thus you'd need to ensure your values are setup to load into it with every request, so it may not be useful with whatever you are planning to do. I tend to use them more often than Zend_Session_Namespace however. Thank you very much J. That really helped. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.