Using PHP5 OO arrays for metatags generation on all pages
Posted: Mon Feb 02, 2009 2:35 pm
Hi, being a newbie at PHP5 OO I've searched on PHP's home site and couldn't find a solution, including on Google unfortunately.
Background...
I'm trying to get modular OO coding for my website via includes, so for example index.php will include the header, content, menu & footer etc. I'm trying to do this so that I can just add XHTML & other bits of PHP where needed.
I want to have my own template class for webpages. The header page containing an include to the template class will be called, passing the tags to it.
The template class will take the metatags & give back the code to be outputted in the header.php. If there's a faster more scalable way for doing this then please tell me, as I always like to try & get my code as hi-performing as possible.
The prob
Here's my code so far for the template class called genMetaTags.php.
Outputs without spaces...
Its driving me nuts...can someone help please.
Background...
I'm trying to get modular OO coding for my website via includes, so for example index.php will include the header, content, menu & footer etc. I'm trying to do this so that I can just add XHTML & other bits of PHP where needed.
I want to have my own template class for webpages. The header page containing an include to the template class will be called, passing the tags to it.
The template class will take the metatags & give back the code to be outputted in the header.php. If there's a faster more scalable way for doing this then please tell me, as I always like to try & get my code as hi-performing as possible.
The prob
Here's my code so far for the template class called genMetaTags.php.
Code: Select all
<?php
class genMetaTags
{
protected $metaTags = array();
//Called when the object is initialised.
function __construct($metaTags)
{
$this->tags = $metaTags;
/*I'll another function to call so the tags & code can be generated
again, if there's a better way please show me how*/
}
//Just in case for reusable code, so it can be overridden
function changeTags($metaTags)
{
$this->tags = $metaTags;
}
//Do I really need this?
function getTags()
{
return $this->tags;
}
};
//Below is my code for header.php, note that I will put this into header.php once I get it working
$metaTags = new genMetaTags(array("1", "2", "3", "woo hoo"));
//$metaTags->tags(array("1", "2", "3", "woo hoo"));
//Show's array contents correctly
//var_dump($metaTags->tags);
$num = count($metaTags->tags);
//echo $num;
for ($i = 0; $i < $num; $i++)
{
print $metaTags->getTags();
}
?>Code: Select all
Array Array Array Array