Jump to content

Unknown function for a class?


nirali35

Recommended Posts

Hello,

I am writing the following class to dynamically generate META tags for each page in the application but having some difficulties in order to make it work properly.
Here is the error I get: [b]Fatal error: Unknown function: createmeta() in /path/to/the/script on line 40[/b]

I am providing you the code for you to understand it better. So if you can please give me some hints!

[code]
if (!class_exists('meta'))
{
class Meta
{
private $page_title;
private $description;
private $sitename;
private $slogan;
private $company_name;
private $webmaster_email;
private $default_keywords;
private $keywords;
private $meta_words;
private $meta;

/**
* Class constructor
*/
function __construct()
{
$this -> meta = CreateMeta(); // create meta tag
}

function __get($atb)
{
return $this -> $atb;
}

function __set($atb, $val)
{
$this -> $atb = $val;
}

private function CreateDesc()
{
// Formulate the description for each page
if (!empty($this -> page_title))
{
$this -> description = $page_title." - ".$this -> description;
}
}

private function CreateKeywords()
{
// Make the keywords of the title lower case
$this -> keywords = strtolower($this -> page_title);

// Replace double spaces with single spaces
$this -> keywords = str_replace("  ", " ", $this -> keywords);

// Make string comma seperated
$this -> meta_words = str_replace(" ", ", ", $this -> keywords);
}

private function CreatePageTitle()
{
// If no page title, use alternative
if (!$this -> page_title)
{
$this -> meta .= '<title>'.$this->sitename.' - '.$this->slogan.'</title>';
}
else
{
$this -> meta .= '<title>'.$this->sitename.' - '.$this -> page_title.'</title>';
}
}

public function CreateMeta()
{
// Create desctiption
$this -> CreateDesc();

// Create Keywords
$this -> CreateKeywords();

// Create Page Title
$this -> CreatePageTitle();

// Append META content to the $meta string for output
$this -> meta .= '<meta name="keywords" content="'.$this -> meta_words.", ".$this->default_keywords.'">\n';
$this -> meta .= '<meta name="description" content="'.$this->description.'">\n';
$this -> meta .= '<meta name="robots" content="index, follow">\n';
$this -> meta .= '<meta name="generator" content="'.$this->company_name.'">\n';
$this -> meta .= '<meta name="author" content="'.$this->company_name.'">\n';
$this -> meta .= '<meta name="revisit-after" content="2 days">\n';
$this -> meta .= '<meta name="resource-type" content="document">\n';
$this -> meta .= '<meta name="copyright" content="Copyright (C) 2006-2007 '.$this->company_name.'">\n';
$this -> meta .= '<meta name="distribution" content="global">\n';
$this -> meta .= '<meta name="rating" content="general">\n';
$this -> meta .= '<meta http-equiv="reply-to" content="'.$this->webmaster_email.'">\n';
$this -> meta .= '<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">\n';

return $this -> meta;
}
}
}

[/code]

Thanks
Link to comment
https://forums.phpfreaks.com/topic/25653-unknown-function-for-a-class/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.