wanting to build an include handler
Posted: Wed Dec 14, 2011 10:07 pm
I would like to build an include handler into the core of my app, yet still have the included variables available in the scope from which it is called.
example:
The trouble is, in my view, when I call Core::_include('include/file'); the variables within the included file are in the scope of Core::_include(), not the local view where it was called.
This is tricky where I include a "config" file for a static menu contents, and then include the decorator object.
Has anyone come up with any slick solutions to this problem?
example:
Code: Select all
<?php
class Core
{
/* ... */
static function _include($path)
{
try {
if(!empty($path) && file_exists($path))
include($path);
else
throw new Exception("Unable to include file at location: {$path}. File does not exist.");
} catch(Exception $e) {
//TODO: Register Error and Log to Syslog
exit($e->getMessage());
}
}
/* ... */
}
?>
This is tricky where I include a "config" file for a static menu contents, and then include the decorator object.
Has anyone come up with any slick solutions to this problem?