My MVC program has a controller (PHP code) and a view (HTML code). The controller uses a RESTful package. Before TBS, my controller looked something like this:
class ParamsController implements RestController {
function execute(RestServer $rest) {
$title = 'My Title';
$html = file_get_contents('my_template.html');
// code to merge the value of $title into $html
return new StringView($html); // Stringview is a class in the RESTful package
}
}
|
Because some of my variables are more complex than the simple assignment to $title, I want to use TBS in a manner similar to this:
class ParamsController implements RestController {
function execute(RestServer $rest) {
$title = 'My Title';
$TBS =& new clsTinyButStrong;
$TBS->LoadTemplate('mytemplate.html');
$TBS->Show(TBS_NOTHING);
return new StringView($TBS->Source); // Stringview is a class in the RESTful package
}
}
|
This doesn't work because TBS is looking for global variables. I changed one statement to
$TBS->LoadTemplate('mytemplate.html','=ParamsController.execute');
|
but that doesn't work, presumably because my TBS calls are within the ParamsController class. I also tried to move the variable into another class:
class ParamsController implements RestController {
function execute(RestServer $rest) {
$TBS =& new clsTinyButStrong;
$TBS->LoadTemplate('mytemplate.html','=GetParams.init');
$TBS->Show(TBS_NOTHING);
return new StringView($TBS->Source); // Stringview is a class in the RESTful package
}
}
class GetParams
{
function init()
{
$title = 'My Title';
}
}
|
This didn't work either, as TBS is still looking for global variables.
I tried to create global variables like this:
class ParamsController implements RestController {
function execute(RestServer $rest) {
$GLOBALS['title'] = 'My Title';
$TBS =& new clsTinyButStrong;
$TBS->LoadTemplate('mytemplate.html');
$TBS->Show(TBS_NOTHING);
return new StringView($TBS->Source); // Stringview is a class in the RESTful package
}
}
|
I really don't like global variables. They seem to violate the spirit of OO. Are there any other suggestions?