Can i use some thing like $_SESSION['name']="asim";

in symfony

On Sat, Aug 15, 2009 at 7:06 PM, DEEPAK BHATIA <[email protected]>wrote:

>
> Hi,
>
> Below is taken from Symfony Chapter 6
>
>
> http://www.symfony-project.org/book/1_2/06-Inside-the-Controller-Layer#chapter_06_user_session
> ===============================
>
>
> User Session
> Symfony automatically manages user sessions and is able to keep
> persistent data between requests for users. It uses the built-in PHP
> session-handling mechanisms and enhances them to make them more
> configurable and easier to use.
>
> Accessing the User Session
> The session object for the current user is accessed in the action with
> the getUser() method and is an instance of the sfUser class. This
> class contains a parameter holder that allows you to store any user
> attribute in it. This data will be available to other requests until
> the end of the user session, as shown in Listing 6-15. User attributes
> can store any type of data (strings, arrays, and associative arrays).
> They can be set for every individual user, even if that user is not
> identified.
>
> Listing 6-15 - The sfUser Object Can Hold Custom User Attributes
> Existing Across Requests
>
> class mymoduleActions extends sfActions
> {
>  public function executeFirstPage($request)
>  {
>    $nickname = $request->getParameter('nickname');
>
>    // Store data in the user session
>    $this->getUser()->setAttribute('nickname', $nickname);
>  }
>
>  public function executeSecondPage()
>  {
>    // Retrieve data from the user session with a default value
>    $nickname = $this->getUser()->getAttribute('nickname', 'Anonymous
> Coward');
>  }
> }You can store objects in the user session, but it is strongly
> discouraged. This is because the session object is serialized between
> requests. When the session is deserialized, the class of the stored
> objects must already be loaded, and that's not always the case. In
> addition, there can be "stalled" objects if you store Propel objects.
>
> Like many getters in symfony, the getAttribute() method accepts a
> second argument, specifying the default value to be used when the
> attribute is not defined. To check whether an attribute has been
> defined for a user, use the hasAttribute() method. The attributes are
> stored in a parameter holder that can be accessed by the
> getAttributeHolder() method. It allows for easy cleanup of the user
> attributes with the usual parameter holder methods, as shown in
> Listing 6-16.
>
> Listing 6-16 - Removing Data from the User Session
>
> class mymoduleActions extends sfActions
> {
>  public function executeRemoveNickname()
>  {
>    $this->getUser()->getAttributeHolder()->remove('nickname');
>  }
>
>  public function executeCleanup()
>  {
>    $this->getUser()->getAttributeHolder()->clear();
>  }
> }The user session attributes are also available in the templates by
> default via the $sf_user variable, which stores the current sfUser
> object, as shown in Listing 6-17.
>
> Listing 6-17 - Templates Also Have Access to the User Session Attributes
>
> <p>
>  Hello, <?php echo $sf_user->getAttribute('nickname') ?>
> </p>If you need to store information just for the duration of the
> current request--for instance, to pass information through a chain of
> action calls--you may prefer the sfRequest class, which also has
> getAttribute() and setAttribute() methods. Only the attributes of the
> sfUser object are persistent between requests.
>
>
>
> On Sat, Aug 15, 2009 at 9:52 AM, sunny<[email protected]> wrote:
> >
> >
> > Can any body give the right technique how to use session handling
> > >
> >
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"symfony users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/symfony-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to