Re: Referencing variable in calling class?

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

 



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