I have a good amount of legacy code written in PHP, which was not written on any particular framework rather it is mostly old-school style (i.e. inline) PHP. However, most of my new code is written on the Kohana 3.1.X framework. Although Kohana does allow both legacy code and Kohana files to coexist on the same Web site, I would like to now wrap up each legacy code file as a view and take full advantage of Kohana's MVC design pattern and URL rewriting. Yet I am encountering problems with my legacy code not being able to access global variables defined from within the view itself (i.e. legacy code) and am not able to utilize inline functions that are trying to see those global variables via the global scope statement. For example:
application/views/legacy.php
$gvar = 5;
function getadminsettings(){
global $gvar;
echo $gvar;
}
application/classes/controller/myctrl.php
...
public function action_legacy() {
// call legacy.php as a view via View::factory()
}
...
Since I have so much legacy code, it is impractical to refactor all of these legacy code files to be true views. How might I treat these files as views or access them as if they were view-like so that I can from-now-on write my logic in the controller and not inline (thereby, following a true MVC design pattern) and then bind variables to these legacy files?
I did look at In PHP, how can I wrap procedural code in a class? but this post doesn't really work in this case because I am dealing with the Kohana framework.
Update:
Kohana appears to be using an output buffer and that is why it is unable to access such global variables in the legacy files. Has anyone been successful in getting a view in Kohana 3.2 to access global variables?