Aleister
Posts: 73
|
Posted: 04/15/2004, 3:51 PM |
|
Hello,
I need to pass variable values thru includable pages like this:
mainpage.php includes:
includable1.php (ccp)
includable2.php (ccp)
in includable1_events.php I set variable $EverythingDone=true
in includable2_events.php I try to read $EverythingDone but it's always NULL even if I make it global before reading its value.
I thing I am missing something, so every help will be highly appreciated.
Thank you,
aleister
|
|
|
peterr
Posts: 5971
|
Posted: 04/15/2004, 4:59 PM |
|
I don't use PHP (only ASP) but since no one yet answered your question I just took some PHP classes at http://www.google.com/search?q=php+define+global+variables and my answer would be as follows:
I believe that you may need to define the variable globally, outside of any functions. For example try putting "$EverythingDone=false" in mainpage.php outside of events (for example above, between or below events), or even at the beginning of the generated code for mainpage.php.
Then in includable1_events.php use the statement "global $EverythingDone" to specify that you will be accessing that global variable and only then use "$EverythingDone=true".
And in includable2_events.php also use "global $EverythingDone" to specify that you will be accessing that global variable before you try to read the value of $EverythingDone.
If this doesn't work please provide more details about "I make it global before reading its value". How do you make it global?
_________________
Peter R.
YesSoftware Forums Moderator
For product support please visit http://support.yessoftware.com |
|
|
Eric
|
Posted: 04/15/2004, 5:44 PM |
|
For global variables use either a session variable or PHP global variables.
To declare a PHP global variable, declare the variable outside any function (ie at the beginning of the script).
<?php
$myvar = "" ;
function myfunction {
global $myvar ; //you must do this
now you can use the variable within this function
You can also use superglobals (need PHP 4.1.0) and address the variable anywhere as :
$GLOBALS["myvar"] = 45 ;
Note no $ used.
Hope this helps,
Eric
}
|
|
|
Aleister
Posts: 73
|
Posted: 04/18/2004, 3:23 PM |
|
I don't have CCS in front of me but I'll try all the ways you suggested as soon as I return to town.
At first I tried this way:
mainfile.php
<?php
global $EverythingDone; //just after <?php
$EverythingDone=1;
...
...
includable_page1.php, just after <?php ->
global $EverythingDone;
includable_page1_events.php, just after <?php ->
global $EverythingDone;
includable_page2.php, just after <?php ->
global $EverythingDone;
includable_page2_events.php, just after <?php ->
global $EverythingDone;
includablepage1_events.php ->
BeforeShow Event on record1 ->
//write your code here
global $EverythingDone;
if (!$EverythingDone)
{
echo "NOT RIGHT - IT'S NULL";
}
I made it global everywhere just to make sure it will be (for test purposes) but it didn't... so I'll try your ways...
Thanks for your replies,
Aleister
|
|
|
peterr
Posts: 5971
|
Posted: 04/19/2004, 12:23 AM |
|
Aleister,
Note that "global $EverythingDone;" in the beginning of mainfile.php may be wrong, as well as some of the other "global $EverythingDone;" statement that you added.
Both mine and Eric's example didn't include such code. It probably should be just:
<?php
$EverythingDone=1;
I don't see any difference between both of our examples, except I specified the exact pages and locations in your project.
More details and examples are available in PHP manual at http://www.php.net/variables.scope
_________________
Peter R.
YesSoftware Forums Moderator
For product support please visit http://support.yessoftware.com |
|
|
|