Today i updated HMVC from 5.1.40 to 5.2.08
I must say it went very smoothly, everything still worked.
I’ve got a performance win from 0.1432 sec to 0.1408 sec.
That’s a lot, thanx!!!
I use the modules:run function to dynamically load all the modules on the page.
In the database i have a lot of tables, most important:
navigations table, module table, a module show table, a layout table and a layoutposition table.
In the module table there are 7 fields, most important: moduleName, moduleController, moduleMethod.
In the layout table you can set per menu item all the modules, in this table are the following fields:
layout_FK_menuId, layout_FK_moduleId, layout_FK_layoutPositionId, layoutWeight, layoutShow
so for instance you have position top left middle right bottom and more, and you have layoutweight 1 2 3 etc.
In the moduleShow table you can set the modules which are show on all pages. Except if you put a field in the layout table with this module with a certain menuId with layoutShow = 0. I’m planning to make an extra field in the moduleShow table where you can set a categorie and in the navigationstable you can asign a menu item to a categorie.
There are 2 queries to get the modules which will be loaded on the current page.
1 gets all the modules from the layout table, and the other all the modules from the moduleShow table.
Then it combines the 2 objects to 1 and deletes all modules which are set to not show on that page.
Then i create a foreach loop where all the modules will loaded into an array: the key is the layoutpositionname + the layoutweight (for instance left1 or right3 or top1) and the value is this method: modules::run($method_name, $parameter1, $parameter2 etc etc…);
private function build_layout()
{
foreach($this->layout_data as $key => $value)
{
if($value->layoutShow == TRUE)
{
$module = $value->layoutPositionName.$value->layoutWeight;
$name = $value->moduleName."/".$value->moduleController."_".
$value->moduleName."_controller/".$value->moduleMethod;
$layout[$module] = modules::run($name, $this->sel_lang, $this->menu_id, $value->modulePar1, $value->modulePar2);
}
}
if(!isset($layout))
{
return false;
}
return $layout;
}
So the value is not a string, but here it executes the modules:run() method. so it load a method from a certain module.
For instance it executes this: modules::run(menu/standard_menu_controller/show, ‘_en’, ‘5’, ‘>= 1’, ‘main-menu’).
So it executes the show method in the standard_menu_controller in the menu module. This show method loads a view file.
So the value is the returned parsed html in the view file.
Then in the main controller in the index i create another loop wich asign each key and value to the main view:
if(is_array($this->layout))
{
foreach($this->layout as $key => $value)
{
$data[$key] = $value;
}
}
So now in the main view i echo all the posible position, if a module is loaded into here:
<?php if(isset($left1)) echo $left1; ?>
So it echoes the correct view in a module: module > controller > method > view
And here you have you dynamic loading!
Thanx wiredesign! 1 question: is this good practice to do it like this? Or do you suppose something else?