Welcome Guest, Not a member yet? Register   Sign In
multi-view (modules) and controllers...
#1

[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
#2

[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?
#3

[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?
#4

[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.
#5

[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;
#6

[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.
#7

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

http://www.duellweb.com/coding/modules-i...iter-hmvc/

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

[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-i...iter-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




Theme © iAndrew 2016 - Forum software by © MyBB