Welcome Guest, Not a member yet? Register   Sign In
Suggestions to improve Globally accessible variable inline with MVC
#1

[eluser]jdav3579[/eluser]
Hi,
I have a script which has a log in variable, which if not set prints a 'log me in' link and if is set puts a 'my account' link instead. the problem is that I have had to define $GLOBALS['loggedin'] at the top of my index page, which is a bad way of doing it.

Here is the code in the constructor for the controller which sets it
Code:
$GLOBALS['loggedin']=$this->redux_auth->logged_in();

The View
Code:
if(!isset($GLOBALS['loggedin']) || $GLOBALS['loggedin']==FALSE)
             print anchor('home/login','Login');
           else
             print anchor('home/login','My Account');

And at the top of the index file
Code:
$GLOBALS['loggedin'];

Can anyone suggest an alternative way of of doing this, I would rather steer away from having to pass a logged in variable to all the views etc, but this mechanism that I have implemented means future developers won't have a clue!!




Theme © iAndrew 2016 - Forum software by © MyBB