kks_krishna Posted July 12, 2007 Share Posted July 12, 2007 HI Friends, How to store the whole object into session? For example, When user login I want to fetch all the details related to user and put into session with single object. And also how to set the values into object. I am very new to PHP object programming. Please help me. Quote Link to comment Share on other sites More sharing options...
teng84 Posted July 12, 2007 Share Posted July 12, 2007 $_SESSION['wow']="put here the value"; you may also want to put session start at the top of you page Quote Link to comment Share on other sites More sharing options...
kks_krishna Posted July 12, 2007 Author Share Posted July 12, 2007 How can i set the more values into object? Like declaring properites and seting the values. so that we need not set more session values. Quote Link to comment Share on other sites More sharing options...
teng84 Posted July 12, 2007 Share Posted July 12, 2007 array? or explain a little bit Quote Link to comment Share on other sites More sharing options...
kks_krishna Posted July 12, 2007 Author Share Posted July 12, 2007 For example, In Java we called its as Beans or ValueObjects to store the values like: Class Test { private firstName; private lastName; public void setFirstName(String firstName) { this.firstName = firstName; } public String getName() { return this.firstName } // all the methods } Like this can we do in PHP. or any other way? Quote Link to comment Share on other sites More sharing options...
teng84 Posted July 12, 2007 Share Posted July 12, 2007 we store data in php like $variable='your value'; and the data type is predetermine by php unlike in java we declare like int or string and the values or variable dont have the $ sign on it now if you talk about object in php we use classes like java do Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted July 12, 2007 Share Posted July 12, 2007 $_SESSION isn't a normal object. It's more of a super global array that transcends page loads for the user (for a period of time). You can create objects from classes in php just the same as java, just refer to the docs for syntax(http://www.php.net/oop5), you can then serialize those objects (http://www.php.net/serialize) and store them in $_SESSION, then on the next page load, unserialize (http://www.php.net/unserialize) the object and use it like before. There are some exceptions...database connections are per page load...they do not store in the session at all. But most other things will. If you are doing any OOP with php, make sure you are using php5 if at all possible. Quote Link to comment Share on other sites More sharing options...
kks_krishna Posted July 12, 2007 Author Share Posted July 12, 2007 Thanks for your help. 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.