ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Modular Extensions - Version 4.3

March 03, 2008 6:10pm

Subscribe [48]
  • #481 / Jul 09, 2008 9:30pm

    wiredesignz

    2882 posts

    @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.

  • #482 / Jul 09, 2008 9:39pm

    codex

    332 posts

    @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.

    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:

    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:

    class Test extends Controller {
    
        function Test()
        {
            parent::Controller();
        }
    
        function index()
        {
            return 'this works';
        }
    
    }

    Test 2:

    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?

  • #483 / Jul 09, 2008 9:45pm

    wiredesignz

    2882 posts

    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

  • #484 / Jul 09, 2008 9:55pm

    codex

    332 posts

    Can you post the URL you are using?

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

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

    Ok

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

    Nope, nothing.

    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.

    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 😊

  • #485 / Jul 09, 2008 10:02pm

    wiredesignz

    2882 posts

    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().

  • #486 / Jul 09, 2008 10:14pm

    a&w

    101 posts

    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?

  • #487 / Jul 09, 2008 10:16pm

    codex

    332 posts

    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().

    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:

    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);
        }

    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!)

  • #488 / Jul 09, 2008 10:36pm

    codex

    332 posts

    Now to get MY_Controller to work…

    Wiki:

    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:

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

    Where does the autoload go?

  • #489 / Jul 09, 2008 10:40pm

    wiredesignz

    2882 posts

    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();

  • #490 / Jul 09, 2008 10:46pm

    wiredesignz

    2882 posts

    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.

  • #491 / Jul 09, 2008 11:16pm

    codex

    332 posts

    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.

    Ok, so for this moment forget I’m using the cascading style.

    I now have a new module ‘modules/public/public.php’. In public.php there’s

    class Public_Controller extends Controller
         {                                            
            function Public_Controller()
            {
                parent::Controller();
    }
    }

    Added $autoload[‘modules’] = array(‘public’); to autoload.

    But get this error:

    Fatal error: Class 'Public_Controller' not found in F:\wamp\www\mextensions\application\modules\site\controllers\site.php on line 3

    It IS possible to extend your modules from another controller, right?

  • #492 / Jul 09, 2008 11:19pm

    wiredesignz

    2882 posts

    @codex, The filename and class name must be the same.

    It is possible, But I have never tried to extend a module controller from another controller, other than when using module methods.

  • #493 / Jul 09, 2008 11:22pm

    codex

    332 posts

    @codex, The filename and class name must be the same and the module must have a `controllers` directory.

    I did that in the first place, but didn’t work. Will try again, maybe made a typo or whatever. And there IS a controllers dir, I think I forgot to add it to the url.

    EDIT: Yes, typo.

    But still getting the error.

    Tried $autoload[‘modules’] = array(‘public_controller’) and $autoload[‘controllers’] = array(‘public_controller’);

  • #494 / Jul 09, 2008 11:30pm

    codex

    332 posts

    You can use Modular Extensions in exactly the same fashion as Matchbox, without using any of the additional features ME provides.

    Well, not EXACTLY. Matchbox handles cascading controllers without issues. (sorry, couldn’t resist 😉)

  • #495 / Jul 09, 2008 11:30pm

    wiredesignz

    2882 posts

    @codex, Is the module named public_controller too, otherwise use the prefix segment public/public_controller

    Wether or not Matchbox allows you to use poor coding style is not my concern either (sorry couldn’t resist) :lol:

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases