Vars not working from require'd doc...

A

Anonymous

Guest
On my site I want to build a User Selectable layout and color scheme feature which passes the layout and color variables around the urls via a formatted string like $urlextra. While all that worked fine one of my require();'ed files variables don't seem to be globalized or available to my other scripts.

The index.php code is this:

(old code edited out)

and the getColors and getTemplate functions are defined in 'layout.php' like so:

(old code edited out)

So it indicates that colorstr is a string that points exactly to where my file supplying the variables is located on my server and because I used require as opposed to include tells me that it hasn't encountered any fatal errors. So why isn't the require working properly? The templatestr (used in the function getTemplate) worked perfectly and supplied the layout variables necessary for the content of the page (just horrendously ugly with all hex colors in one, missing, file). $scrollbar and $bgcolor were just css variables for the templates (and were also contained in layout/colorsets/default.php).

Any help would be very appreciated.

PS. This is the string I use to pass variables through the url as I have yet to implement an effective session/login system.

$urlextra="&style=" . $style . "&c=" . $c;

but that's mostly because I have yet to implement an effective session/login system. Everything in it's time I guess.
 
Hello :lol:

my questions:
what do you use $c for?


if ($colorset_name=="Arc-Corp Classic" && $style=="") {
$c='default';
} elseif ($colorset_name=="$skin2" && $style=="") {
$c='skin_2';
} elseif (isset($style)) {
$c=$style;
}


why do you use =="$skin2" instead of =="skin_2" in the first elseif ?

Bye :roll:
 
it could help ?

<?php
// this uses phpdoc comments
// php doc will be available in the near future from http://pear.php.net/packages.php
// the format of the comments are in the pear manual on http://pear.php.net/manual/en/packages.phpdoc.php

//require('lib/config.php');
//require('lib/global.php');
// require_once('layout.php');
$layout = new layout();

$layout->style = "blue"; //$style;
$layout->skin = $_REQUEST['skin'];
$layout->template_name = $template_name;

$colorstr = $layout->getColors();
$templatestr = $layout->getTemplate();
rprint($layout);
require_once($colorstr);
require ($templatestr);

/**
* A class for doing skins, layouts, and colors
*
* @access public
* @package
* @version
*/
class layout
{
/**
* Short Description
* Long Description
* @access public
*/
function getColors() {
if ($this->skin=="default" || $this->skin=="") {
$this->colorset_name="Arc-Corp Classic";
} elseif ($this->skin=="skin_2") {
$this->colorset_name="Under Development";
}; // end if

if ($this->colorset_name == "Arc-Corp Classic" && $this->style == "") {
$this->c='default';
} elseif ($this->colorset_name=="$skin2" && $this->style=="") {
$c = 'skin_2';
} elseif (isset($this->style)) {
$this->c=$this->style;
}; // end if
$out ="layout/colorsets/" . $this->c . ".php";
return $out;
} // end method

/**
* Short Description
* Long Description
* @access public
*/
function getTemplate() {
if ($this->template_name=="Arc-Corp Classic" && $this->style=="") {
$this->skin='default';
} elseif ($this->template_name=="skin_2" && $this->style=="") {
$this->skin='skin_2';
} elseif (isset($this->style)) {
$this->skin=$this->style;
}; // end if

if ($this->skin=="default") {
$this->template_name="Arc-Corp Classic";
} elseif ($this->skin=="skin_2") {
$this->template_name="Under Development";
}; // end if

$out = "layout/templates/" . $this->skin . ".php";
return $out;
}// end method
} // end cls

?>
 
Thanks and sorry but, I got it working.

The first "skin2" was an error but I fixed up the code and it works now.

These are the relevant contents of my layout.php file:
Code:
 $template_name;
 $layout_1="Arc-Corp Classic";
 $layout_2="Under Development";
 $skin;
 $c;
 $cstring;
 $string;
 $layout;
 $colorset_name;
 $colorset_1="Arc-Corp Classic";
 $colorset_2="Dark Scheme 1";
 $colorset_3="Crisp";
 $urlextra="&layout=" . $layout . "&c=" . $c;
 $urlbits;

function getColors($colors) {
 global $colorset_name,$c,$colorset_1,$colorset_2;

	if ($colorset_name=="$colorset_1" && $colors=="") {
		$c='default';
	} elseif ($colorset_name==="$colorset_2" && $colors=="") {
	   	$c='skin_2';
	}
	if (isset($colors)) $c="$colors";
	if ($c=="default") $colorset_name="$colorset_1";
	if ($c=="skin_2") $colorset_name="$colorset_2";

	$cstring="layout/colorsets/" .$c. ".php";
	return $cstring;
}

function getTemplate($thetemplate) {
	global $template_name,$layout,$layout_1,$layout_2;

	if ($template_name=="$layout_1" && $thetemplate=="") {
		$layout='default';
	} elseif ($template_name==="$layout_2" && $thetemplate=="") {
	   	$layout='skin_2';
	}
	if (isset($thetemplate)) $layout="$thetemplate";
	if ($layout=="default") $template_name="$layout_1";
	if ($layout=="skin_2") $template_name="$layout_2";
	$tstring="layout/templates/" .$layout. ".php";
	return $tstring;
}

if ($c=="") { $c="bluescheme"; $colorset_name="$colorset_1"; }
if ($c=="bluescheme") $colorset_name="$colorset_1";
if ($c=="dark1") $colorset_name="$colorset_2";
if ($c=="crisp") $colorset_name="$colorset_3";
if ($layout=="") { $layout="default"; $template_name="$layout_1"; }
if ($layout=="default") $template_name="$layout_1";
if ($layout=="skin_2") $template_name="$layout_2";

$c is used for passing the color variable around in the url until I make it cookie or session/db based. I'm still working on the user registration/login system so this seemed like the most expediant way to pass variables around, the next thing I have to do is change all my "index.php?action=pagenames" into pagenames.php files so the javascript from the select menus takes you to the right place afterwards.

http://www.arc-corp.net if you're interested. I won't be using applications made by other people in the code as it defeats the purpose of coding ones own site, I think. Part of the point of this for me is to learn how.

With this code at the top of every page file the templates work as expected.

Code:
include('lib/config.php');
include('layout.php');
 $colorstr=getColors($c);
include($colorstr);
 $templatestr=getTemplate($layout);
include($templatestr);
include('lib/global.php');
[/code]
 
Back
Top