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 Separation - PHP5 (Modules)

July 02, 2009 12:38am

Subscribe [88]
  • #301 / Mar 17, 2011 8:14am

    wiredesignz

    2882 posts

    Try with the module name also.

    $this->load->view('sample/sample/some_view');
  • #302 / Mar 17, 2011 11:09pm

    Keat Liang

    29 posts

    Try with the module name also.

    $this->load->view('sample/sample/some_view');

    oh that solve the problem.  thanks a lot !

  • #303 / Mar 30, 2011 9:24pm

    Noor

    12 posts

    Why Modules::run() doesn’t working.

    Here is my code
    modules/home/controller/home.php

    class Home extends MX_Controller {
    
        function __construct()
        {
            parent::__construct();
        }
    
        function index()
        {
            $this->load->view('home_view');
        }
    }

    and my view

    <h1>Welcome to CodeIgniter!</h1>
    
    <?php echo Modules::run('home/test'); ?>
    
    The page you are looking at is being generated dynamically by CodeIgniter.
    
    
    Page rendered in {elapsed_time} seconds

    modules/home/controllers/test.php

    class Test extends MX_Controller {
    
        function __construct()
        {
            parent::__construct();
        }
    
        function index()
        {
            echo 'something';
        }
    }

    and in the log file I get this error

    ERROR - 2011-03-31 08:22:16—> Module controller failed to run: home/test

    Help please

  • #304 / Mar 30, 2011 10:37pm

    wiredesignz

    2882 posts

    Your code is attempting to run the home controller test method. Try:

    <?php echo Modules::run('home/test/index'); ?>
  • #305 / Mar 31, 2011 2:39am

    Noor

    12 posts

    Your code is attempting to run the home controller test method. Try:

    <?php echo Modules::run('home/test/index'); ?>

    Thanks, it’s working now.
    But, should I always type method name? including index method?

  • #306 / Mar 31, 2011 3:12am

    Noor

    12 posts

    I can not run controller with same name even though the module is different.
    modules/events/controllers/latest.php

    class Latest extends MX_Controller {
    
        function __construct()
        {
            parent::__construct();
        }
    
        function index()
        {
            echo 'several latest events';
        }
    }

    modules/news/controllers/latest.php

    class Latest extends MX_Controller {
    
        function __construct()
        {
            parent::__construct();
        }
    
        function index()
        {
            echo 'several latest news';
        }
    }

    in the home_view.php I echo something like this

    <?php echo Modules::run('news/latest/index'); ?>
    
    
    <?php echo Modules::run('events/latest/index'); ?>

    and it’s output :
    several latest news
    several latest news

    Why?

  • #307 / Mar 31, 2011 3:20am

    wiredesignz

    2882 posts

    Why?, Because PHP does not allow you to load two classes with the same class declaration.

  • #308 / Apr 03, 2011 6:01am

    Element 80

    2 posts

    Is there currently any built-in method with the system to return a list of available modules?

    I’m trying to figure out a way to create a sort of user-side pick-and-choose module manager, so that if I have a module for an RSS feed and a module for a mailing list, user A can opt for the RSS, user B can opt for the mailing list, and user C can go with both, but I need to know that the modules exist first to give them the choice.

    I also want to make sure I’m not misusing this - “core” Controller, Model and View files for my system can/should still be run from the original application/____ folders and not application/modules/[so forth], right? I assumed this was the case, though the example on the wiki made this a little unclear.

  • #309 / Apr 03, 2011 6:26am

    theprodigy

    653 posts

    Is there currently any built-in method with the system to return a list of available modules?

    I’m trying to figure out a way to create a sort of user-side pick-and-choose module manager, so that if I have a module for an RSS feed and a module for a mailing list, user A can opt for the RSS, user B can opt for the mailing list, and user C can go with both, but I need to know that the modules exist first to give them the choice.

    The way I’ve handled this before was to keep track of everything in the database. You can build a “modules” table, with columns for name, folder_name, and active.

    The difference between name and folder_name are:
    Name: Human readable
    Folder_name: the actual module folder name

    This is so you can give your users options for ‘RSS’ and “Maillist”, but name your modules ‘rssfeed’ and ‘mail_list’.

    The active column is a boolean field, so you can turn access to your modules on and off.

    If you don’t want to go the database route, the only other options I can think of is to do a scandir of the modules directory, then loop through the returned array using is_dir to make sure the current element is a directory, and not a file (make sure you also check for ‘.’ and ‘..’).

  • #310 / Apr 03, 2011 6:31am

    Element 80

    2 posts

    That’s essentially what I want to do, but I need to know the plugin exists before it can be added to the database. Preferably, I’d like to be able to make adding modules in as simple as dropping the module into the directory and running an “Update modules” method. It sounds like the best way to do this would be the scandir method you outlined?

  • #311 / Apr 03, 2011 3:06pm

    theprodigy

    653 posts

    That’s essentially what I want to do, but I need to know the plugin exists before it can be added to the database. Preferably, I’d like to be able to make adding modules in as simple as dropping the module into the directory and running an “Update modules” method. It sounds like the best way to do this would be the scandir method you outlined?

    I would have your “Update Modules” method do the scandir, and compare the array returned to the folder_name column in the db.modules table, and insert any modules not found.
    That sounds kinda like what you are looking for.
    Maybe you can even setup a config/install.php file per module, with the data you want inserted into the db for that module (name, active, etc).

  • #312 / May 24, 2011 6:53am

    B3ll4triX

    17 posts

    How to access library in other module?

  • #313 / May 24, 2011 7:31am

    hungnm144

    7 posts

    How to access library in other module?

    if you want load model from other module (or helper, language)
    Code example:

    $this->load->model(‘name_module/module_model.php’);
    $this->load->helper(‘name_module/module_helper.php’);

  • #314 / May 24, 2011 9:03am

    B3ll4triX

    17 posts

    i have module A with library L1, and i want to use library L1 in module B, how to access library L1 in module A from module B?

  • #315 / May 24, 2011 10:50am

    jellep

    1 posts

    Hello everbody,

    I try to implement modules at my Codeigniter. It does not work and i don’t know why. I did
    the steps but when i try to acces trough the url its gives a 404. Somebody know whats wrong.

    Thanks!

    Bye

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

ExpressionEngine News!

#eecms, #events, #releases