Jump to content
Larry Ullman's Book Forums

$Live Variable


Recommended Posts

Hi Larry,

 

Newbie questions:

 

On page 60, I am getting slightly confused.

 

$live is set to False

 

1) So in effect is this saying that we set the $live variable to False, so this equates to the site not being live(production mode), but in development mode(localhost)?

 

Now on page 61 it says:

 

if(!$live)

 

 

Since $live is set to False in the config file, !$live equates to True(1), because NOT false is True.

 

2) So does  'if (!$live)' equate to:

 

if(true == true)

 

because

 

(!$live) == !FALSE == TRUE

 

 

 

3) How does the site detect if it is live(in production mode) or in development mode(localhost)?

 

So let me know if my understanding of what you wrote is correct.

 

On page 60

 

i. You set $live to False to indicate that the site is not live

ii. If the site is live, or in production mode, $live is set to True, which is represented in the else statement on page 61

 

4) Where does it then assign True to $live if the site is in production mode?

 

Sorry for the basic questions, but I am still learning.

 

Thank you

 

 

Link to comment
Share on other sites

Sorry for the confusion with the reverse logic! Yes, basically the $live variable reflects "are we in production or not?" It might be easiest to follow if you think about that question rather than the values. So setting it to false means we're not in production (we're testing). 

 

Then, checking if (!$live) means "if we're not in production". In other words, if $live has a false value... If $live has a false value, I wouldn't describe it as "if true == true", rather than "if not false", which means "if true". 

 

The site doesn't "detect" whether it's in live or production mode; you tell it through the assigning of a value. When you're ready to go live, you'd assign the value true to it. 

 

Let me know if anything is still unclear!

Link to comment
Share on other sites

Hi Larry,

 

Thanks for your quick response.

 

I think the logic is my main issue here.

 

So this is my understanding:

 

(!$live) means

 

NOT False, which in turns means TRUE.

 

So on page 61

 

'if (!$live)'

 

means

 

if($live is NOT False)  ie TRUE

 

then

 

do whatever...............

 

This is where I had problems understanding what was going on. So my understanding now is;

 

if (!$live) evaluates to True, then $live must still be False, which in turn means that it is still in development mode and not live.

 

If (!$live) evaluated to False, this would mean that $live would be True, which would mean the site is live.

 

I hope my understanding is correct, because it took me pacing up and down for a good while to understand what is going on.

 

My Final questions is:

 

QU 1: When the site does indeed go live, on what page in the book, or where in the script does TRUE get assigned to the $live variable to signify a change from development to live mode?

 

 

QU 2: How does the site know when it indeed does go live?

 

QU 3: What piece of code is used to see if the site is live, and where does this code reside?

 

Hope the above made sense.

 

Thanks Larry

Link to comment
Share on other sites

So this is my understanding:

 

(!$live) means

 

NOT False, which in turns means TRUE.

I don't think that's a good way to think of it because the $live variable could have a true or false value. More truthfully put, it means "if the opposite of the $live value is TRUE".  

 

This is where I had problems understanding what was going on. So my understanding now is;

 

if (!$live) evaluates to True, then $live must still be False, which in turn means that it is still in development mode and not live.

 

If (!$live) evaluated to False, this would mean that $live would be True, which would mean the site is live.

 

That is exactly correct.

  

QU 1: When the site does indeed go live, on what page in the book, or where in the script does TRUE get assigned to the $live variable to signify a change from development to live mode?

 

You'd change the second line of config.inc.php (page 60) from false to true.

 

QU 2: How does the site know when it indeed does go live?

 

It "knows" because you've manually changed that value. 

 

QU 3: What piece of code is used to see if the site is live, and where does this code reside?

 

The second line of config.inc.php (page 60).

 

In short, the config file defines the value of LIVE (also, to be clear, it's a constant, not a variable). You set that value, the rest of the site looks at it to know what to do. 

Link to comment
Share on other sites

Larry,

 

Thank you for this! I now understand.

 

For some reason, I thought that $live was automatically changed from false to true, from some other part of the code in the application.

 

I didn't realise I had to manually change the $live constant myself.

 

Now onto understanding the rest of the code......Here goes!

Link to comment
Share on other sites

 Share

×
×
  • Create New...