Re: OO Theory Question
| From: | Justin Patrin | Date: | Tue, 17 Aug 2004 18:52:48 +0000 |
| Subject: | Re: OO Theory Question | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-194076@lists.php.net to get a copy of this message | ||
On Tue, 17 Aug 2004 12:03:56 -0600, Jed R. Brubaker
<jrb21398@hotmail.com> wrote:
> Hi all! I could use some perspective on a project that I am currently
> working on.
>
> I am trying to utilize OO to make my PHP easier, but I keep running into
> problems that revolve around the stateless nature of the web.
>
> Consider the following: I have a login class that is instantiated at the top
> of every page. It can log you in, check to see if you are logged in, etc.
> This class has an assortment of class variables such as userID, userType,
> etc.
>
> It would be great if I could make a reference to $login->userType on any
> given page, but I run into errors as the login class gets reinstantiated on
> every page.
>
> A solution is to set all of these variables into $_SESSION, but the appeal
> of classes is that I might be able to maintain all of my information in a
> related location, and not in the session.
>
> I am sure that this is a problem that many of you more experienced (than I)
> developers have run into. Is there a solution? And ideas?
>
Instead of re-instantiating the object, store it in the session.
if($loginSuccessful) {
$_SESSION['authObj'] = new AuthObj($loginUsername);
or
$_SESSION['authObj'] =& $existingAuthObj;
}
--
DB_DataObject_FormBuilder - The database at your fingertips
http://pear.php.net/package/DB_DataObject_FormBuilder
paperCrane --Justin Patrin--