php template generator can't fetch data
I have a problem with a templategenerator function that can't fetch some dynamic data and replace markers in a HTML with the data.
I have created a function inside my Main class that sets markers that I define
function GetMarkers($markers = array()) {
foreach($markers as $key => $value) {
$this->mark开发者_开发问答ers[strtoupper($key)] = $value;
}
return $this->markers;
}
I define some markers in class.rooms.php
$markersRoom = array();
$markersRoom["###ROOMS###"] = '<a href="#" onclick="return showRBox();" class="boxOpener">'. $rTxt .'</a>';
$markersRoom["###ROOMS###"] .= '<div class="roomBox">';
$markersRoom["###ROOMS###"] .= '<ul class="roomItems">';
while($row = mysql_fetch_array($sql)) {
$markersRoom["###ROOMS###"] .= '<li>';
$markersRoom["###ROOMS###"] .= '<p><a href="index.php?page=sr&room='. $row["room"] .'&floor='. $_GET["floor"] .'&wall='. $_GET["wall"] .'&envi='. $_GET["envi"] .'&fpanel='. $_GET["fpanel"] .'">'. $row["descr"] .'</a></p>';
$markersRoom["###ROOMS###"] .= '</li>';
}
$markersRoom["###ROOMS###"] .= '</ul>';
$markersRoom["###ROOMS###"] .= '</div>';
Main::GetMarkers($markersRoom);
}
and puts them into the GetMarkers function.
These markers are to be used in a HTML template that are read by my TemplateGenerator function
function TemplateGenerator($template) {
/* Get content from the html template */
$data = file_get_contents($template);
if(isset($this->markers)) {
/**************************************************
* Match each key in $this->markers array
* and replace with the correct value
***************************************************/
foreach($this->$markers as $key => $value) {
if(preg_match("/". preg_quote($key) ."/", $data, $matches)) {
$data = str_replace($key, $value, $data);
} else {
$data = $data;
}
}
Main::TxtOutput($data);
} else {
if(!empty($data)) {
echo $data;
} else {
die("An error occured");
}
}
}
When I do a print_r($markers)
inside GetMarkers() I can see all data from $markersRoom["###ROOMS###"]
correctly but when I do it inside TemplateGenerator, the data is lost.
TemplateGenerator is called in my index.php inside a switch($page) with
$main->TemplateGenerator("templates/rooms.html");
Where rooms.html contain the marker ###ROOOMS###
It reads the HTML file correctly but doesn't have any data from GetMarkers to put into it so it just outputs ###ROOMS###
Am I missing something somewhere?
精彩评论