Re: Referencing variable in calling class?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Paul,

To be honest, I'm still finding my way around as to how I want to approach
this application, but my question is valid in some sense no matter which
direction I pursue.

I finally opted to make the relevant variables in my front controller class
static, so I could directly reference them from optionally included
downstream code.

This has worked well so far, at least in my early experimentation with a
code layout.

Thanks for your reply all the same!

M is for Murray


On Sun, Jan 11, 2009 at 4:39 PM, Paul M Foster <paulf@xxxxxxxxxxxxxxxxx>wrote:

> On Sun, Jan 11, 2009 at 10:33:30AM +1000, Murray wrote:
>
> > Hi All,
> >
> > I'd like to reference the value of a variable in a class that called the
> > current piece of code via a require_once.
> >
> > In essence, I have a 'front controller' class that builds the page to be
> > displayed depending on several criteria.
> >
> > One issue I'm having is that when a user logs out of my application, I
> > destroy the cookie that indicated the user was logged in during my
> preRender
> > process, and then go onto display the 'logged out' page. Unfortunately, I
> > have a page element that indicates whether the user is logged in or not,
> and
> > I assume because the cookie destruction is being sent down in that page
> > request, when that page renders it still appears as if the user is logged
> > in, because the cookie still exists until after that page is rendered.
> >
> > So, I thought perhaps as part of my logout routine, I could set a
> variable
> > that my 'are you logged in or out' code could check and use to override
> > whether or not it displays the 'login' url or the 'logout' url.
> >
> > I thought that in that code I should be able to check the value of a
> public
> > variable that is in my front controller class, but it appears I can't?
> >
> > So, pseudo chain of processing would be something like this:
> >
> > - call index.php
> > - instantiate front loader class
> > - perform pre-render processing, if logging out, set public variable in
> > class to true
> > - call actual page to be rendered via require_once
> > - in page being rendered, call function from separate file that displays
> > 'login / logout' url
> > - in that function test public variable in front controller class to see
> if
> > true
> > - if true, regardless of whether or not the cookie still 'appears' to
> exist,
> > display 'login' url because user has logged out
> >
> > However, am I right in thinking that the function that displays the login
> /
> > logout url is actually unaware of the existence of the front controller
> > class at the point at which it is being called?
> >
> > M is for Murray
>
> I'm not quite sure why you don't force the login/logout page to use the
> front controller. Here's how I do it: I set various variables, and check
> the login status (I use $_SESSION variables to hold user ID and
> encrypted password). If the user is not logged in, I force the
> controller to be the login controller, regardless of whatever page the
> user *wants* to display. Then I go ahead with instantiating the
> controller, in this case, the login controller. So essentially, if the
> user is logged in, I go ahead and instantiate whatever controller they
> specify. But if they're not logged in, I force the login controller to
> be the one which is instantiated. (In my case, the "front controller"
> isn't really a class as other controllers are. It's just a bunch of
> routines and function calls in index.php.)
>
> Does that make sense?
>
> Paul
>
> --
> Paul M. Foster
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux