Hey Frocco,
My project isn't anywhere near finished and I'm ripping my code apart to take the modules::run out, so bear with me when I try to simplify my code.
A page in my cms has sections like header, left, middle, right, footer. Every section can hold 1 or more elements like a text or menu view. A page also has one template with the section predefined in it.
Supersimple page template:
Code:
<!DOCTYPE html>
<html>
<head>
<style>
</style>
</head>
<body>
<div id="header">
<?php if (isset($header)) echo $header; ?>
</div>
<div id="left">
<?php if (isset($left)) echo $left; ?>
</div>
<div id="middle">
<?php if (isset($middle)) echo $middle; ?>
</div>
<div id="right">
<?php if (isset($right)) echo $right; ?>
</div>
<div id="footer">
<?php if (isset($footer)) echo $footer; ?>
</div>
</body>
</html>
I have one page controller which matches a slug to a page in the database and finds out which elements go with which sections. That data is reformatted into something that looks like:
Code:
Array
(
[header] => Array
(
[10] => Array
(
[module] => html
[view] => test
[settings] =>
)
[20] => Array
(
[module] => flexslider
[view] => content
[settings] =>
)
)
)
Here you can see that there are 2 elements found for section header. In a foreach loop the output for the section is created:
PHP Code:
foreach ($elements as $section => $element) {
foreach ($element as $block) {
// here should be a check if a certain library is already loaded
// ..
$this->load->library($block['module'].'/'.$block['module']); // this loads the html or flexslider library from the module with the same name
$html = $this->$block['module']->$block['view']($block['settings']); // this call the method test from the html or the method content from the library flexslider which will create the output for the views.
if (!isset($sections[$section])) $sections[$section] = '';
$sections[$section] .= $html;
}
}
After this all HTML for all sections is created and the array of $sections can be the data for the page template.
PHP Code:
$this->load->view("templates/{$pageTemplate}", $sections);
And boom, your page with all the good stuff is put to screen...
Hope this helps.
-Roger