[eluser]popovich[/eluser]
Hello everyone,
before I get there myself (and it's been a while now), I would appreciate any help from this forum.
My objective is to load multiple models dynamically, based on the database reference. These models are the modules, which can be switched back and forth on the fly, through admin interface of the CMS I am building. Basically, db holds a model name (like, 'press'), its position on the page, and the order it appears in regard to other modules. However, the sorting of this kind causes no problems. It is a 'different object name', as it is read in the user guide.
In the
main controller I try to initialize models
Code:
function init_modules( $modules ) {
$retour = array();
if( count($modules) < 1 ){
return false;
}else{
foreach ( $modules as $mod ) {
$data = array();
$dynamic_model = 'modules/mm_'.$mod;
$dynamic_view = 'modules/mv_'.$mod;
$this->load->model($dynamic_model, 'temp');
# every model has this function, so it can start running
$data = $this->temp->initialize();
$retour[]['mod_content'] = $this->parser->parse($dynamic_view, $data);
}
}
return $retour;
}
Container for modules in the main layout
Code:
{mods}
<div class="module_right">
{mod_content}
</div>
{/mods}
1 of 2 models being loaded, the 'press'
Code:
<?php
class Mm_press extends Model {
function Mm_press (){
parent::Model();
}
function initialize() {
return array('press'=>"do press");
}
}
?>
The parser template for the model 'press'
Code:
<em>Press Releases</em>
<p>
{press}
</p>
2 of 2 models being loaded, the 'store'
Code:
<?php
class Mm_store extends Model {
function Mm_store (){
parent::Model();
}
function initialize() {
return array('store'=>"do store");
}
}
?>
The parser template for this very model
Code:
<em>Find a Store</em>
<p>
{store}
</p>
It all seems to work properly except for two lines in the controller, I guess:
Code:
$this->load->model($dynamic_model, 'temp');
$data = $this->temp->initialize();
The "temp" variable is not being evaluated, when called in a loop. It is being evaluated just once and when loading another model, it still references the first model. So if I load first "store", then "press", the "store" view is being parsed correctly, the "press" — not. If first goes "press", then "store", the "press" view is being parsed correctly, the store stays unparsed.
My question is: where is the catch? Or, how do I reference a dynamically loaded model?
Any help is greatly appreciated.