I'm sure there's an easy answer to this.
I have a highly configurable internet application of which I won't bore you with details. However the relevant stuff is that they can define a number of database fields to be a certain type (Eg: select, open, timestamp, etc - more will be added in time)
To do this I have defined a TypeFactory:
class TypeFactory {
public function getType($type) {
switch (true) {
case preg_match('/select/', $type): return new SelectType();
case preg_match('/open/', $type): return new OpenType();
// add more as needed
}
}
}
|
SelectType:
class SelectType {
private $_title'
// superfluous stuff removed
public function setTitle($title) { $this->_title = $title; }
public function getTitle($title) { return $this->_title; }
public function getHTML() {
return "<select name=$name><option value=opt1>Option1<option value=opt2>Option2></select>";
}
}
|
OpenType:
class OpenType {
private $_title'
// superfluous stuff removed
public function setTitle($title) { $this->_title = $title; }
public function getTitle($title) { return $this->_title; }
public function getHTML() {
return "<input type=text>";
}
}
|
PHP code:
$tbs = new clsTinyButStrong;
$tbs->LoadTemplate("display.html");
// get requested data from DB
// use the TypeFactory class to convert the data to an array of classes
$tbs->MergeBlock('blkData', $data);
$tbs->Show();
|
HTML code:
. . .
<table>
[blkData;block=begin]
<tr>
<td>[blkData.getTitle()]</td>
<td>[blkData.getHTML()]</td>
</tr>
[blkData;block=end]
</table>
|
Currently the getHTML() functions are returning the html script and displaying this as raw text. How can I get it to to run the html script from the getHTML function calls?
Thanks for any advice.