So I would like to create a modular website. This website would get the page and module information from a DB. Each page would have a number of modules that would be loaded when the page is displayed. Each module's controller file (PHP code) is in separate PHP files. I know I will have to include those files when I need them. But I have some scope or some other issue which I don't know how to solve. So here is what I have and what I would like:
Code: Select all
/* this class is responsible for retrieveing the module information
* activate the modules, etc...
*/
class pageController {
protected $modules = array();
protected $somevar;
public function __construct(){
$this->somevar = 'asdadasd';
/* set up some vars, call some other functions */
$this->getModuleInfo();
}
private function getModuleInfo(){
/* ok, I know the modules and what files to include */
require_once 'module_file.php';
/* and now let's call the contructor on the module */
$nameOfModule = 'nameOfModule';
$m = new $nameOfModule();
}
}
$var = new pageController();Code: Select all
class nameOfModule extends pageController {
public function nameOfModule(){
/* and here is the problem! */
var_dump( $this->somevar );
/* the output is: null
* and what I want is the actual value of the pageController::$somevar;
*/
}
} I know that require and include will make the included file's scope to the scope where the file is included. Do you think it's got something to do with it?
Well, thanks for the help in advance anyway...