CodeIgniter Forums
Modular Extensions - Version 4.3 - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=22)
+--- Thread: Modular Extensions - Version 4.3 (/showthread.php?tid=6550)



Modular Extensions - Version 4.3 - El Forum - 07-09-2008

[eluser]wiredesignz[/eluser]
@a&w, Maybe you could create a simple application using Matchbox and then swap Modular Extensions in and see what happens.

I for one would be interested to read the results of your findings.


Modular Extensions - Version 4.3 - El Forum - 07-09-2008

[eluser]codex[/eluser]
[quote author="wiredesignz" date="1215667833"]@a&w, Maybe you could create a simple application using Matchbox and then swap Modular Extensions in and see what happens.

I for one would be interested to read the results of your findings.[/quote]

Actually I'm testing ME right now. And if it works I'll convert my MB app to ME. Maybe I'm doing something wrong but I'm not getting the expected results.

As a very, very simple test I created 2 dirs in /modules: 'test' and 'test2'.

From the wiki:
Code:
class Default_controller extends Controller
{
    function Default_controller()
    {
        parent::Controller();
    }
    
    function _remap($page, $content = '')
    {
        switch ($page)
        {
            case 'index':
            case 'test':
                $content = modules::run('test');
                break;

            case 'test2':
                $content = modules::run('test2');
                break;
        }        

        $data = array(
            'title'   => 'Page title goes here',
            'content' => $content,
            'page'    => $page,
        );
        
        $this->load->view('default_layout' , $data);
    }
}

Test:
Code:
class Test extends Controller {

    function Test()
    {
        parent::Controller();
    }

    function index()
    {
        return 'this works';
    }

}

Test 2:
Code:
class Test2 extends Controller {

    function Test2()
    {
        parent::Controller();
    }

    function index()
    {
        return 'this works too';
    }
}

Test gets called and outputs 'this works'. Great. But when you enter test2 as the first (or second) segment you still get 'this works' (index is called, not test2).

What am I doing wrong?


Modular Extensions - Version 4.3 - El Forum - 07-09-2008

[eluser]wiredesignz[/eluser]
Can you post the URL you are using?

BTW, If you want to call modules directly from the URL you dont need Default_Controller at all.

index.php/test or index.php/test2 will work.

And rather than use modules::run() inside a controller you can load->module or $autoload['modules']

In ME5.0 you can also use method chaining: echo $this->module{'test')->index(); in a parent controller


Modular Extensions - Version 4.3 - El Forum - 07-09-2008

[eluser]codex[/eluser]
[quote author="wiredesignz" date="1215668757"]Can you post the URL you are using?[/quote]

http://localhost/mextensions/test2 or http://localhost/mextensions/test2/test2

Quote:BTW, If you want to call modules directly from the URL you dont need Default_Controller at all.
Ok

Code:
index.php/test or index.php/test2 will work.
Nope, nothing.

Quote:And rather than use modules::run() inside a controller you can load->module or $autoload['modules']
Oddly enough load->module doesn't return anything, while modules::run() does.

Code:
In ME5.0 you can also use method chaining: echo $this->module{'test')->index();
Oh yeah, I completely forgot about that. It's just been a few days that my host upgraded to PHP5 :-)


Modular Extensions - Version 4.3 - El Forum - 07-09-2008

[eluser]wiredesignz[/eluser]
Yes codex, $this->load->module() only loads the controller, it doesn't run a method. Whereas modules::run() does both.

Once the controller is loaded you can call it like a library. ie: $this->test->index()

Also reset your $routes now that you removed Default_Controller (If you haven't already).

It does work I can assure you of that. ME4.2 and ME5.0 are very stable now.

Also you are using `return` in each Test module... you know that will show no output. Try echo or even load->view().


Modular Extensions - Version 4.3 - El Forum - 07-09-2008

[eluser]a&w[/eluser]
Is ME5.0 released or just 4.2? I only see 4.2 from the wiki. You update fairly frequently, have you thought to svn it somewhere?


Modular Extensions - Version 4.3 - El Forum - 07-09-2008

[eluser]codex[/eluser]
[quote author="wiredesignz" date="1215669772"]Yes codex, $this->load->module() only loads the controller, it doesn't run a method.

Once the controller is loaded you can call it like a library. ie: $this->test->index()

Also reset your $routes now that you removed Default_Controller (If you haven't already).

It does work I can assure you of that. ME4.2 and ME5.0 are very stable now.

Also you are using `return` in each Test module... you know that will show no output. Try echo or even load->view().[/quote]

Ah yes, I see. It works now. Thanks!

I'll play around with it a bit and see if I'm able to convert the lot.

Used this code:
Code:
function index()
    {
        $this->load->module('test');
        $content = $this->module('test')->index();      

        $data = array(
            'title'   => 'Page title goes here',
            'content' => $content
        );
        
        $this->load->view('default_layout' , $data);
    }

Quote:Also you are using `return` in each Test moduleā€¦ you know that will show no output. Try echo or even load->view().
Yeah, I did try to echo at first, but I was getting a something about reference error (I forget the exact message). Return seems to work fine though :-) (will do it the proper way when not testing!)


Modular Extensions - Version 4.3 - El Forum - 07-09-2008

[eluser]codex[/eluser]
Now to get MY_Controller to work...

Wiki:
Quote:If you need to run methods in a base controller define them in another module controller and use the controller autoload functionality.

Created modules/base/controllers/base_controller.php. base_controller.php holds 3 classes:

class Base_Controller extends Controller
class Admin_Controller extends Base_Controller
class Public_Controller extends Base_Controller

I have a 'site' module that extends from Public_Controller:

Code:
class Site extends Public_Controller
{
    //$autoload['base/base_controller'];
    
    function Site()
    {
        parent::Public_Controller();
    }
}

Where does the autoload go?


Modular Extensions - Version 4.3 - El Forum - 07-09-2008

[eluser]wiredesignz[/eluser]
Just a point to note: $this->module('test') and $this->load->module('test') is the same function because the controller ($this) is the loader ($this->load). Don't use both calls together.

Method chaining means the controller is loaded and then the method is called. ie: $this->module('test')->index();


Modular Extensions - Version 4.3 - El Forum - 07-09-2008

[eluser]wiredesignz[/eluser]
For the MY_Controller issue, Make your Admin_Controller and Public_Controller extend Controller not Base_Controller, then add Base_Controller to autoload and call its methods / varaibles as needed, just like a library.

Use application/config/autoload.php :ie $autoload['controllers'] = array('base_controller');

Note: In the latest verison of ME4.2 $autoload['controllers'] is now $autoload['modules'] and ME5.0.27 will be changed to match.

EDIT:
Sorry codex, I didn't notice right away you are using that cascading controller thing. It's a bit difficult for me to advise on this as I would never build an application like that.