i'm trying to use list to split up an array, and use a dynamic variable to pick the array from a set of arrays.
the arrays contain the URL of a file iwish to include on a page, the url of any javascript i may want to include, and an extra empty slot for possible future use.
example:
$home = array ("index.html","slideshow.js","");
$about = array ("about.html","popup.js","");
so let's say that the user selects $page via clicking on link. ?page=home
the value of $$page ($home) selects the specific array $home("index.html","slideshow.js","");, includes the index.html file in the body, and the slideshow.js file in the head.
my problem is that i am using list() to split the array into $content, $popup, and $extra. and it's not returning things as expected.
here's the test.php file:<?
include("header.inc");
if (isset($content)) {
include($content);
} else {
include($home[0]);
}
?>...and the header.inc:<? include("config_url.inc"); ?>
<?
list($content,$popup,$extra) = each($$page);
?>
<? if (isset($popup)) {include($popup);} ?>...and config_url.inc<?
$home = array ("index2.html","","");
$about = array ("about.html","","");
// and on and on
?>
...but it spits out the content in the head of the html and won't spit anything into the body. (in the code above, i removed the html.) i get these errors:
Warning: main(0) [function.main]: failed to create stream: No such file or directory in W:\www\mboosters\test.php on line 7
Warning: main() [function.main]: Failed opening '0' for inclusion (include_path='.;W:\usr\local\PHP\includes;W:\usr\local\PHP\pear') in W:\www\mboosters\test.php on line 7
(line 7 being include($content)
and when testing the values, i get:
$content: 0
$page: about
$page[0]: a
$popup: about.html
so where all am i going wrong??try doing just $$page instead of each($$page)thanks... actually, i JUST this moment solved it:<?
$home = array ("index2.html","","");
$about = array ("about.html","popup.js","");
list($content,$popup,$extra) = $$page;
if ($popup != "") {include($popup);}
if (isset($$page)) {
include($content);
} else {
include($home[0]);
}
?><?php
/* set array for content, script, and anything extra */
$home = array ("/index2.html","","");
$about = array ("path/to/about.html","scripts/popup.js","");
$links = array ("path/to/links.html","scripts/chromeless.js","");
/* et cetera */
/* split the $$page array into manageable variables */
list($content,$script,$extra) = $$page;
/* inject standard HTML code */
echo "<html>";
echo "<head>";
/* insert the HTML header... you can use this instead of all the code above, provided you put it into your header.inc file */
include("header.inc");
/* include script (like for popups, etc.) in the <head>, unless nothing is set into the $script part of the $$page array */
if ($script != "") {include($script);}
/* inject standard HTML code */
echo "</head>";
echo "<body>";
/* include content (if the $$page variable is set... if not, include first selection from $home array */
if (isset($$page)) {
include($content);
} else {
include($home[0]);
}
/* insert the footer: copyright, credits, disclaimer, etc... you can put the code below this into your footer.inc file rather than putting it down below */
include("footer.inc");
/* inject standard HTML code */
echo "</body>";
echo "</html>";
?>
the arrays contain the URL of a file iwish to include on a page, the url of any javascript i may want to include, and an extra empty slot for possible future use.
example:
$home = array ("index.html","slideshow.js","");
$about = array ("about.html","popup.js","");
so let's say that the user selects $page via clicking on link. ?page=home
the value of $$page ($home) selects the specific array $home("index.html","slideshow.js","");, includes the index.html file in the body, and the slideshow.js file in the head.
my problem is that i am using list() to split the array into $content, $popup, and $extra. and it's not returning things as expected.
here's the test.php file:<?
include("header.inc");
if (isset($content)) {
include($content);
} else {
include($home[0]);
}
?>...and the header.inc:<? include("config_url.inc"); ?>
<?
list($content,$popup,$extra) = each($$page);
?>
<? if (isset($popup)) {include($popup);} ?>...and config_url.inc<?
$home = array ("index2.html","","");
$about = array ("about.html","","");
// and on and on
?>
...but it spits out the content in the head of the html and won't spit anything into the body. (in the code above, i removed the html.) i get these errors:
Warning: main(0) [function.main]: failed to create stream: No such file or directory in W:\www\mboosters\test.php on line 7
Warning: main() [function.main]: Failed opening '0' for inclusion (include_path='.;W:\usr\local\PHP\includes;W:\usr\local\PHP\pear') in W:\www\mboosters\test.php on line 7
(line 7 being include($content)
and when testing the values, i get:
$content: 0
$page: about
$page[0]: a
$popup: about.html
so where all am i going wrong??try doing just $$page instead of each($$page)thanks... actually, i JUST this moment solved it:<?
$home = array ("index2.html","","");
$about = array ("about.html","popup.js","");
list($content,$popup,$extra) = $$page;
if ($popup != "") {include($popup);}
if (isset($$page)) {
include($content);
} else {
include($home[0]);
}
?><?php
/* set array for content, script, and anything extra */
$home = array ("/index2.html","","");
$about = array ("path/to/about.html","scripts/popup.js","");
$links = array ("path/to/links.html","scripts/chromeless.js","");
/* et cetera */
/* split the $$page array into manageable variables */
list($content,$script,$extra) = $$page;
/* inject standard HTML code */
echo "<html>";
echo "<head>";
/* insert the HTML header... you can use this instead of all the code above, provided you put it into your header.inc file */
include("header.inc");
/* include script (like for popups, etc.) in the <head>, unless nothing is set into the $script part of the $$page array */
if ($script != "") {include($script);}
/* inject standard HTML code */
echo "</head>";
echo "<body>";
/* include content (if the $$page variable is set... if not, include first selection from $home array */
if (isset($$page)) {
include($content);
} else {
include($home[0]);
}
/* insert the footer: copyright, credits, disclaimer, etc... you can put the code below this into your footer.inc file rather than putting it down below */
include("footer.inc");
/* inject standard HTML code */
echo "</body>";
echo "</html>";
?>