CodeIgniter Forums
multi-view (modules) and controllers... - 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: multi-view (modules) and controllers... (/showthread.php?tid=20266)



multi-view (modules) and controllers... - El Forum - 07-03-2009

[eluser]SMaton[/eluser]
Hi everyone,

I'm currently learning how to use CodeIgniter and I have read through the tutorials and wiki pages (not all, but a lot). I've especially checked the multi-view examples because that's the way I'd like to setup my pages.

I've a C++/C#/Java background, so I'm familiar with MVC. The difference I see with MVC php is the dynamic page generation and thus the dynamic usage of models and views.

The examples I've seen do a sequential loading of the views and implement the combined view logic into one single controller. Thus this controller is holding the logic for several views.

I wonder if it's possible to "sequentially load" controllers, too. To explain: Imagine that my page is build out of small blocks which can be enabled and disabled by the user through a configuration panel. Ideally I would implement those blocks as different views and with-coming controllers (one for each view). So, in my example, I would rather load the controllers than the views.

Is this possible using CodeIgniter and/or php?

Best regards,
Stefan


multi-view (modules) and controllers... - El Forum - 07-03-2009

[eluser]R. Oerlemans[/eluser]
Code:
<?php

class Controllername extends Controller {

    function Controllername()
    {
        parent::Controller();    
    }
    
    function index()
    {
        // Header
        $this->load->view('header');
        
        // Query
        $row = 'Query and thing'; // Row the usersetting
        
        // Check if block1 is true
        if($row->displayBlock1){
            $this->load->view('blocks/block1');
        }        

        // Check if block2 is true
        if($row->displayBlock2){
            $this->load->view('blocks/block2');
        }        

        // Footer
        $this->load->view('viewname');
            
    }
}

You mean like this?


multi-view (modules) and controllers... - El Forum - 07-03-2009

[eluser]SMaton[/eluser]
Yes, that's the dynamic loading of the different views. But then, I'd have one controller per view containing all the logic code for that specific view. I.E. a Auth_Controller for the user authentication view, a News_controller for the news view etc.

That way I can either decide to make each view a "single page" or embed them as a block within a multi-view without having to rewrite the logic code.

Your example would require me to re-implement the logic code for block1 and block2 and the "viewname" block.

I hope I'm clear with what I'd like to achieve?


multi-view (modules) and controllers... - El Forum - 07-03-2009

[eluser]garymardell[/eluser]
Whats wrong with using a model/library for each block and then maybe even use a helper to show the block in the view.


multi-view (modules) and controllers... - El Forum - 07-03-2009

[eluser]R. Oerlemans[/eluser]
[quote author="SMaton" date="1246660938"]Yes, that's the dynamic loading of the different views. But then, I'd have one controller per view containing all the logic code for that specific view. I.E. a Auth_Controller for the user authentication view, a News_controller for the news view etc.

That way I can either decide to make each view a "single page" or embed them as a block within a multi-view without having to rewrite the logic code.

Your example would require me to re-implement the logic code for block1 and block2 and the "viewname" block.

I hope I'm clear with what I'd like to achieve?[/quote]

You also could send the mySQL data to the viewer and check it in that.
Code:
<?php if($displayData->displayBlock1): ?>
<div class"block" id="block1">
<p>lol</p>
</div>
&lt;?php endif; ?&gt;



multi-view (modules) and controllers... - El Forum - 07-03-2009

[eluser]SMaton[/eluser]
[quote author="garymardell" date="1246661117"]Whats wrong with using a model/library for each block and then maybe even use a helper to show the block in the view.[/quote]

I have to dig a little bit deeper into this framework to see how this library concept works and if it's usable for my intentions. Thanks for pointing me into that direction.


multi-view (modules) and controllers... - El Forum - 07-03-2009

[eluser]R. Oerlemans[/eluser]
There also is a module library. You can found it here:

http://www.duellweb.com/coding/modules-in-code-igniter-hmvc/

I don't know if that's where you lookin' for. My English isn't really good.


multi-view (modules) and controllers... - El Forum - 07-03-2009

[eluser]SMaton[/eluser]
[quote author="R. Oerlemans" date="1246674495"]There also is a module library. You can found it here:

http://www.duellweb.com/coding/modules-in-code-igniter-hmvc/

I don't know if that's where you lookin' for. My English isn't really good.[/quote]

Yes, that seems to be what I was looking for. Thanks for the link !

Best regards and have a nice week-end,
Stefan