i am designing a few pages. the pages have a few main divs and that is how i am inserting the background(with css)
i can render the whole background to the browser but i dont get how to nest divs inside divs with OOP.
any help would be greatly apreciated!

regards.

<?php 

class page{

var $leftContent;

var $rightContent;

var $styles = "styles/bglayout.css";

var $title = "Man of Honor";

var $keywords = "Man of Honor, MoH, socom 1, socom 2, socom 3, socom combined assault, socom confrontation, call of duty 4, cod4, clan, psychoraptor, pallaso_loko";

var $buttons = array('Home' => 'index.php', 'Roster' => 'roster.php', 'Code of Conduct' => 'coc.php', 'Members Lounge' => 'Members_lounge.php', 'Register' => 'register.php');

//Set new functions

function SetLeftContent($newleftcontent){
    $this->leftContent = $newleftcontent;
}

function SetRightContent($newrightcontent){
    $this->rightcontent = $newrightcontent;
}

function SetStyle($newstyle){
    $this->style = $newstyle;
}

function SetTitle($newtitle){
    $this->title = $newtitle;
}

function SetKeywords($newkeywords){
    $this->keywords = $newkeywords;
}

function SetButtons($newbuttons){
    $this->buttons = $newbuttons;
}

//Display functions

function DisplayTitle(){
	echo "<title> $this->title </title>\n";
}

function DisplayKeywords(){
	echo "<meta name=\"keywords\" content=\"$this->keywords\" />\n";
}

function DisplayStyles(){
	echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"$this->styles\" />\n";
}

function DisplayHeader(){
echo '<div class="page_header">
</div>';
}

function DisplayContentTop(){
echo '<div class="content_top">
</div>';
}

function DisplaySpacer(){
echo '<div class="content_spacer">
</div>';
}

function DisplayContentBottom(){
echo '<div class="content_bottom">
</div>';
}

function DisplayLeftContent(){
echo $this->leftContent;
}

function DisplayRightContent(){
echo $this->rightcontent;
}

function DisplayMenu($buttons){

}

function Display(){
	echo "<html>\n<head>\n";
	$this->DisplayTitle();
	$this->DisplayKeywords();
	$this->DisplayStyles();
	echo "</head>\n<body>\n";
	$this->DisplayHeader();
	$this->DisplayContentTop();
	$this->DisplaySpacer();
	$this->DisplayContentBottom();
	$this->DisplayMenu($this->buttons);
	$this->DisplayrightContent($this->rightcontent);
	echo "</body>\n</html>\n";
	}




}



?>

imo this is a difficult way of rendering a page, but anyway. It would be possible to use an array to define your page flow. In turn that could be used to specify the tags to create, and point to a variable or function containing the tags content. Is there a special reason you're trying it this way ?

well im just starting to learn OOP with php.
idk what is the best way to do it. the examples about cars and bycicles work n stuff but now im ready for something more.

I think I would create an object representing one div/tag, with the possibility to contain zero or more objects of the same type. The top object would represent the html, the first one in it the header, and so on. You can build your whole page like this, and then delegate the creation of the output. Since I'm not at home at the moment, I can't write you code representing my thoughts, but I'll check back later.

<?php
	class Tag {
		var $name = '';
		var $attributes = array ();
		var $content = array ();
		
		function Tag($a_name) {
			$this->name = $a_name;
		}
		
		function AddAttribute($a_key, $a_value) {
			$this->attributes[$a_key] = $a_value;
		}
		
		function AddContent($a_content) {
			$this->content[] = $a_content;
		}
		
		function ToString() {
			$retval = '';
			$retval = '<' . $this->name . ' ';
			
			foreach ($this->attributes as $key => $value) {
				$retval .= $key . '="' . $value . '" ';
			}
			$retval .= '>';	
			
			foreach ($this->content as $mixed) {
				if (is_string($mixed)) {
					$retval .= $mixed;
				}
				else if (is_object($mixed)) {
					$retval .= $mixed->ToString();
				}
			}
			
			$retval .= '</' . $this->name . '>';
			return $retval;
		}
	}
	
	$html = new Tag('html');
	
	$head = new Tag('head');
	
	$title = new Tag('title');
	$title->AddContent('OOP Example');
	
	$head->AddContent($title);
	$html->AddContent($head);
	
	$body = new Tag('body');
	$body->AddAttribute('text', '#800000');
	$body->AddAttribute('bgcolor', '#F0FFF0');
	$body->AddContent('This is a test');
	$html->AddContent($body);
	
	echo $html->ToString();
?>
Comments
nice post thanks

i like how you did that, thats neat how you basically make your own tags. thank you.
ill have to put this into my designs sometime
regards!

This article has been dead for over six months. Start a new discussion instead.