CodeIgniter Forums
Loading modules per page using CI - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Loading modules per page using CI (/showthread.php?tid=42818)



Loading modules per page using CI - El Forum - 06-20-2011

[eluser]Sillysoft[/eluser]
Ok getting confused on how to use CI to do this. Im planning to use CI for my next big project but trying to figure out how to do this in CI.

In my current non CI site I have a template that I use, inside that html template I specify sections like so:

Code:
<html>
<head></head>
<body>
<div id="column_left">&lt;?php echo $section1; ?&gt;</div>
<div id="column_middle">&lt;?php echo $section2; ?&gt;</div>
<div id="column_right">&lt;?php echo $section3; ?&gt;</div>
&lt;/body&gt;
&lt;/html&gt;

When a visitor visits my site I load this template and query the database to find all "modules" that I have assigned in the db to each of those sections above. All a module is, is a php script that specifically does a action such as read_rss.php. This php file reads an rss feed and displays the results. Or I could have a stories.php file that queries my db for stories that display the last 10. I simply grab those files and using output buffering do the following:

Code:
foreach($page_modules AS $curr_module)
    {

        $module_section = intval($curr_module->section);
        $module_file = $curr_module->modfile;
        $module_path = MODS .$module_file;

        if(is_file($module_path))
        {

            ob_start();
            include($module_path);
            ${'section' .$module_section} .= ob_get_contents();
            ob_end_clean();

        }

    }

This loops through each php script, includes it and gets the contents of the include and assigns it to the proper variable which could be $section1, $section2 or $section3 depending on where it was assigned to in the db. So $section1 might have 5 modules assigned to it then $section2 could have 10 modules assigned to it and so on. How could I do something like this in CI?


Loading modules per page using CI - El Forum - 06-20-2011

[eluser]InsiteFX[/eluser]
CodeIgniter WIKI HMVC Modules

InsiteFX


Loading modules per page using CI - El Forum - 06-20-2011

[eluser]Sillysoft[/eluser]
Looking for examples for hmvc.


Loading modules per page using CI - El Forum - 06-20-2011

[eluser]Sillysoft[/eluser]
[quote author="InsiteFX" date="1308633059"]CodeIgniter WIKI HMVC Modules

InsiteFX[/quote]

So would you suggest I create a model that queries db for the modules for each page, pass the results to the controller which passes them to the view, then in the view loop through them using the hmvc plugin like so?

Code:
&lt;?php

foreach($results AS $rows)
{

echo modules::run('mod/' .$rows->modname);

}

?&gt;

Something like that?


Loading modules per page using CI - El Forum - 06-20-2011

[eluser]osci[/eluser]
You could just fine.

modules::run is a NICE feature as you'll see.

btw you would add method and params if needed.


Loading modules per page using CI - El Forum - 06-20-2011

[eluser]InsiteFX[/eluser]
You can also use this in these in your controllers
Code:
$this->load->module('module_name');

modules::run('module/controller/method', $param, $...);

InsiteFX


Loading modules per page using CI - El Forum - 06-20-2011

[eluser]Sillysoft[/eluser]
[quote author="InsiteFX" date="1308652291"]You can also use this in these in your controllers
Code:
$this->load->module('module_name');

modules::run('module/controller/method', $param, $...);

InsiteFX[/quote]

How would I pass the output from the module in the controller to the view? Pretty much all of my modules would return some type of html for the view either displaying rows from the db or feed from rss, forms etc.


Loading modules per page using CI - El Forum - 06-20-2011

[eluser]InsiteFX[/eluser]
Sorry it should be like this in your view file

Code:
// controller
$data = array();

$data['param'] = 'parameters to pass';

// view
&lt;?php echo Modules::run('module/controller/method', $param, $...);

I missed some of the code when I copied it.

InsiteFX