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 - HMVC version 5.4

January 29, 2011 1:58am

Subscribe [99]
  • #286 / Oct 04, 2012 9:09am

    nsyed

    3 posts

    I’m not offended at all. Just stating a fact.

    CI conventions indicate that controllers and their ancestors provide core functionality they are not defined as libraries.

    If you need a base controller you can create a core directory in your module and include the parent class as per your normal PHP directives or place them into the application/core directory to be autoloaded.

    Also if you load a base controller as a library then you are instantiating a redundant controller instance which seems pointless.

    In future it might be worth looking at the Modules::autoload() method to accommodate loading core files from modules too.

    Alright awesome then =). I’m new to CI so correct me if I’m wrong. Btw, HMVC is a great addition to CI, I really do like it but of course, stuff needs to be modified when scaling out applications.

    Including the parent class as per normal PHP directives defeats the purpose of having the class loaded through the CI system, I’d need to include the class into every controller I make within the module - this is why I wanted to have the class autoloaded since it will be used regardless for all controllers in the module. And placing my extended core classes into core defeats the purpose of individual modularity - and plus, I have other extensions of core classes using the “subclass_prefix.”

    The Modules::autoload() function does not go to the depth of /module/module_name/core, but rather stays at application level. I’d need to modify this if I wanted this to look for a core folder within a module.

    Just because a core class is placed in a “libraries” folder doesn’t mean that it has to act like a library. Would I rather put it in a folder called “core” for the sake of indicating it is a core class? Yes, I would love to lol.

  • #287 / Oct 11, 2012 10:20am

    becky.resler

    2 posts

    I have a question about routing with modules. I have a setup similar to the following:

    /application/
    |--- modules/
       |--- somemodule/
          |--- config/
             |--- routes.php
          |--- controllers/
             |--- admin.php
             |--- foobar.php
             |--- somemodule.php
          |--- models/
          |--- views/

    And inside my routes.php file in the module, I have something similar to the following:

    $route['somemodule']        = 'somemodule';
    $route['somemodule/foobar'] = 'foobar';
    $route['admin/somemodule']  = 'admin';

    The first 2 routes work just fine, but the admin route does not.

    Based on the searching/research I’ve done, the Modular Extension script is not made to handle routes (in a routes file within the module) with a path that starts with something other than the module name out-of-the-box. I know that I can put the routes in the main routes file, but I’d like to keep them with the module if at all possible.

    Has anyone been able to find a solution to get routes like the 3rd one above to work when put in a module routes file?

  • #288 / Oct 31, 2012 6:33pm

    ZaLiTHkA

    29 posts

    Hey wiredesignz, I have a question.. Suppose you might think it a strange request, especially considering that HMVC is designed to check for a module first, followed by the default location if no module is found.

    Is it possible to prevent any views loading from the default ‘views’ folder? For example, using this controller:

    class Display extends MX_Controller {
     public function index() {
      $this->load->view('display');
     }
    }

    By default, this will look first for ‘application\modules\display\views\display.php’, then if that fails it will look for ‘application\views\display.php’. I want it to only check the modules path for the view and fail if it doesn’t exist.. Is this possible?


    For some reason, while under Windows CI with HMVC runs fine when I remove the default views folder, when I run the same app on Linux it tells me it can’t find the controller. When I create the views folder again (even leaving it empty), the error goes away.

    I also tried commenting out the middle section of HMVC’s view() method, like this:

    /** Load a module view **/
    public function view($view, $vars = array(), $return = FALSE) {
     list($path, $_view) = Modules::find($view, $this->_module, 'views/');
     
     // if ($path != FALSE) {
     //  $this->_ci_view_paths = array($path => TRUE) + $this->_ci_view_paths;
     //  $view = $_view;
     // }
     return $this->_ci_load(array('_ci_view' => $view, '_ci_vars' => $this->_ci_object_to_array($vars), '_ci_return' => $return));
    }

    Thinking that it would try load the module’s view and not the default, but even with the view in the ‘module\views’ folder, I get an error saying it can’t load ‘display.php’.

    Any ideas…?

  • #289 / Nov 01, 2012 1:30am

    GamBeaT

    2 posts

    Hey,

    I’ve wanted to download HMVC, but in the “downloads” it says there is nothing to download. do I have to open everything in source and just copy paste the code ? :O

  • #290 / Nov 01, 2012 1:59am

    wiredesignz

    2882 posts

    Hey wiredesignz, I have a question..

    ...Is it possible to prevent any views loading from the default ‘views’ folder? ...

    Any ideas…?

    Alter the MY_Loader.php file and add a modified view method.

    Check after the modules::find() method that $this->_module value is valid and that the $path value is false. This will indicate that the view does not exist in the module.

  • #291 / Nov 01, 2012 2:26am

    wiredesignz

    2882 posts

    Hey,

    I’ve wanted to download HMVC, but in the “downloads” it says there is nothing to download…

    Go back to Bitbucket and look more thoroughly.

  • #292 / Nov 01, 2012 2:30am

    ZaLiTHkA

    29 posts

    Hey,

    I’ve wanted to download HMVC, but in the “downloads” it says there is nothing to download. do I have to open everything in source and just copy paste the code ? :O

    That confused me a bit when I first found this as well… On the ‘Downloads’ page, then select the ‘Branches’ tab and you’ll see links on the right hand side.

    Alter the MY_Loader.php file and add a modified view method.

    Check after the modules::find() method that $this->_module value is valid and that the $path value is false. This will indicate that the view does not exist in the module.

    Ok cool, thanks.. I’ll try that when I get home tonight and see what I can do, not actually sure if what I’m trying to do will actually work anyway, but there’s only one way to find out. 😊 I think I’ll base it on an optional extra parameter so I don’t end up breaking something else in the process.

  • #293 / Nov 01, 2012 10:27am

    GamBeaT

    2 posts

    thanks, got it 😊 now got a question, how does this feature works with URI language indentifier ?

  • #294 / Nov 01, 2012 2:10pm

    samitrimal

    32 posts

    I just downloaded codeigniter 2.1.3 and Hmvc 5.4 ,  I found that the controllers method is running two times. here below is the code for

    <?php
    class Index extends MX_Controller
    {
        function index()
        {
          //  $this->load->view('index/index');
           echo "samit
    ";
        }
    }
    ?>

    And i Got the result
    samit
    samit

    I think this is a bug.

  • #295 / Nov 02, 2012 1:14am

    wiredesignz

    2882 posts

    @samitrimal, Be sure to post back when you discover that it’s not a bug.

  • #296 / Nov 02, 2012 11:19am

    samitrimal

    32 posts

    hi @wiredesignz,Please check the log generated when i used the code. I am using your extension for first time. I don’t know if i am wrong

    modules/test/controllers/index.php
    <?php
    class Index extends MX_Controller
    {
        public function index(){
            
              $this->load->model('test/tests_m');
             $this->tests_m->get_();
                $this->load->view('test/index/welcome_message');
        }
    }
    modules/test/models/test_m.php
    <?php
    class Tests_m extends CI_Model
    {
        public function get_(){
            echo get_class();
        }
    }
    ?>
    modules/test/views/index/welcome_message.php
    <?php echo __FILE__;?>

    Output :
    /var/www/contact_ci/application/third_party/MX/Loader.php
    /var/www/contact_ci/application/third_party/MX/Loader.php
    Tests_m/var/www/contact_ci/application/third_party/MX/Loader.php
    Tests_m/var/www/contact_ci/application/modules/test/views/index/welcome_message.php/var/www/contact_ci/application/modules/test/views/index/welcome_message.php

    Finally Log generated when running the code.

    DEBUG - 2012-11-02 20:57:50—> Config Class Initialized
    DEBUG - 2012-11-02 20:57:50—> Hooks Class Initialized
    DEBUG - 2012-11-02 20:57:50—> Utf8 Class Initialized
    DEBUG - 2012-11-02 20:57:50—> UTF-8 Support Enabled
    DEBUG - 2012-11-02 20:57:50—> URI Class Initialized
    DEBUG - 2012-11-02 20:57:50—> Router Class Initialized
    DEBUG - 2012-11-02 20:57:50—> Output Class Initialized
    DEBUG - 2012-11-02 20:57:50—> Security Class Initialized
    DEBUG - 2012-11-02 20:57:50—> Input Class Initialized
    DEBUG - 2012-11-02 20:57:50—> Global POST and COOKIE data sanitized
    DEBUG - 2012-11-02 20:57:50—> Language Class Initialized
    DEBUG - 2012-11-02 20:57:50—> Language Class Initialized
    DEBUG - 2012-11-02 20:57:50—> Config Class Initialized
    DEBUG - 2012-11-02 20:57:50—> Loader Class Initialized
    DEBUG - 2012-11-02 20:57:50—> Database Driver Class Initialized
    DEBUG - 2012-11-02 20:57:50—> User Agent Class Initialized
    DEBUG - 2012-11-02 20:57:50—> Template Class Initialized
    DEBUG - 2012-11-02 20:57:50—> Session Class Initialized
    DEBUG - 2012-11-02 20:57:50—> Helper loaded: string_helper
    DEBUG - 2012-11-02 20:57:50—> Session routines successfully run
    DEBUG - 2012-11-02 20:57:50—> Controller Class Initialized
    DEBUG - 2012-11-02 20:57:50—> Model Class Initialized
    DEBUG - 2012-11-02 20:57:50—> File loaded: application/modules/test/models/tests_m.php
    DEBUG - 2012-11-02 20:57:50—> Model Class Initialized
    DEBUG - 2012-11-02 20:57:50—> File loaded: application/modules/test/views/index/welcome_message.php
    DEBUG - 2012-11-02 20:57:50—> File loaded: application/modules/test/views/index/welcome_message.php
    DEBUG - 2012-11-02 20:57:50—> Final output sent to browser
    DEBUG - 2012-11-02 20:57:50—> Total execution time: 0.0311

    Hope, you will believe it now.

  • #297 / Nov 02, 2012 6:18pm

    wiredesignz

    2882 posts

    ...Hope, you will believe it now.

    There is no bug in Modular Extensions or Codeigniter causing this.

    Your code is the source of all of the problems.

    The first problem is that the Index Controller index() method is also the constructor for the class so it will be accessed twice, once when the class is loaded and again when CI runs.

  • #298 / Nov 02, 2012 11:16pm

    samitrimal

    32 posts

    Ah , I didnt realized that, index() still works in php 5.3.8

  • #299 / Nov 17, 2012 8:34am

    Dale

    1 posts

    @wiredesignz

    Just wanted to say thanks for this, works fantastic, great!

  • #300 / Nov 18, 2012 10:00am

    ZaLiTHkA

    29 posts

    Hey Wiredesignz.. I’m starting a new project and I wanted to check something on your HMVC Wiki page, but BitBucket won’t let me access the page without logging in first now. I don’t have a BitBucket account and I don’t really have any need for one. Any idea what’s going on…?

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

ExpressionEngine News!

#eecms, #events, #releases