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]
  • #106 / Sep 09, 2011 12:59pm

    haydenp

    46 posts

    Hi wiredesignz

    I’ve just taken the following steps:

    1. Removed application/core/MY_Lang.php
    2. Downloaded and installed new MX files from bitbucket
    3. Added a __construct() method to application/third_party/MX/Lang.php with a call to the CI class as follows:

    class MX_Lang extends CI_Lang
    {
        function __construct()
        {
            $index_page = CI::$APP->config->item('index_page');
        }
    
        public function load($langfile, $lang = '', $return = FALSE, $add_suffix = TRUE, $alt_path = '', $_module = '')    {
    
            //$index_page = CI::$APP->config->item('index_page');
    
            ...
        }
    }

    This results in: Fatal error: Call to a member function item() on a non-object in ... application/third_party/MX/Lang.php ...

    4. I modify the code in #3 above to the following:

    class MX_Lang extends CI_Lang
    {
        function __construct()
        {
            //$index_page = CI::$APP->config->item('index_page');
        }
    
        public function load($langfile, $lang = '', $return = FALSE, $add_suffix = TRUE, $alt_path = '', $_module = '')    {
    
            $index_page = CI::$APP->config->item('index_page');
    
            ...
        }
    }

    This runs fine - no errors.

    5. I added debug code to the __construct() in both MX/Base.php and MX/Lang.php ... the CI class in Base.php is correctly instantiated before the MX_Lang class in Lang.php ... it just does not make sense why CI is not available in a __construct() in MX/Lang.php!?!

    Sidenote: Heard you are from NZ? Watch the rugby this morning?

  • #107 / Sep 10, 2011 12:23am

    austintbiggs

    40 posts

    Where can I download the HMVC code? Also how do I install it?

  • #108 / Sep 10, 2011 10:48am

    pickupman

    1317 posts

    Where can I download the HMVC code? Also how do I install it?

    You can get it from bitbucket.org.

  • #109 / Sep 12, 2011 5:45am

    donjim

    7 posts

    Is it possible to install the HMVC code in a Codeigniter v 1.7.2 project?

  • #110 / Sep 12, 2011 9:40am

    pickupman

    1317 posts

    Is it possible to install the HMVC code in a Codeigniter v 1.7.2 project?

    Yes, but using an older version of CI at this point should be discouraged.

  • #111 / Sep 12, 2011 10:29am

    donjim

    7 posts

    Is it possible to install the HMVC code in a Codeigniter v 1.7.2 project?

    Yes, but using an older version of CI at this point should be discouraged.

    Well, my project is growing larger and larger. but guess that i have to take the time to move it to 2.x soon.

  • #112 / Sep 14, 2011 4:54pm

    liri

    50 posts

    Indeed HMVC is not compatible with latest CI (the develop branch) due to the system/core/Loader.php variables defined as protected (as Boris clearly noted and confirmed. @see http://ellislab.com/forums/viewthread/179560/P40/#884541).

    Any ideas on a solution without hacking core around?

  • #113 / Sep 14, 2011 8:45pm

    wiredesignz

    2882 posts

    Protected class variables in CI_Loader do not prevent Modular Extensions HMVC from working with CI 2.1.0-dev

    If you discover there are specific errors, then post them in this thread.

  • #114 / Sep 15, 2011 3:10am

    liri

    50 posts

    Well those were my errors:

    --> Severity: Notice  --> Undefined property: Code::$_ci_classes
    --> Severity: Notice  --> Indirect modification of overloaded property MY_Loader::$_ci_cached_vars

    What I did was to load system/core/Loader.php and change all the protected vars there to public. On my next try those errors were resolved.

    The HMVC version I use is from bitbucket.
    The CI version I use is ‘git clone https://github.com/EllisLab/CodeIgniter.git’


    Have I missed something?

  • #115 / Sep 15, 2011 3:21am

    wiredesignz

    2882 posts

    @liri, Modular Extensions HMVC does not have a Code class and the $_ci_classes variable is in the CI_Loader class so the first error is from your own code.

    It appears that you have created your own MY_Loader::$_ci_cached_vars variable which conflicts with the CI_Loader variable.

    Post some code showing the errors with their respective line numbers description and the problem classes from your application.

  • #116 / Sep 16, 2011 8:11am

    liri

    50 posts

    Right, the Code class belongs to my test project but I’m not doing any call to $_ci_classes, nor to ci_cached_Vars. Since the Code class is a module/controller and is using hmvc then it’s hmvc doing it.

    Fact is, when I changed the system/core/Loader.php protected declarations to public, that worked.

    In application/core/ I simply copied the sample MY_Loader.php and MY_Router.php which contain the default

    <?php (defined('BASEPATH')) OR exit('No direct script access allowed');
    
    /* load the MX_Loader class */
    require APPPATH."third_party/MX/Loader.php";
    
    class MY_Loader extends MX_Loader {}

    and the same for MY_Router.php as well as I added a MY_Controller.php which extends CI_Controller.

    Also I’m looking at third_party/MX/Loader.php and it extends CI_Loader so I don’t see why the protected vars are even a problem…


    Can you possibly explain the install process (if it maybe changed for develop branch?) or link to where it’s described.

  • #117 / Sep 16, 2011 2:50pm

    broncha

    9 posts

    Hi guys
    I have just come up with a few line of codes which I think will be helpful for modules handling both administrative and public tasks
    I work with following structure in modules
    |—-modulename
      |—-controllers
        |—-admin
          |—-modulename.php
        |—-modulename.php
      |—-models
      |—-views
        |—-admin
        |—-public

    So i used to define routes to access the administrative modules such that admin/modulename routes to modulename/admin/modulename

    Add this method to APPPATH/core/MY_Router.php in class MY_Router
    The method is a slightly modified version of the original HMVC Router method

    public function locate($segments) {        
            
            $this->module = '';
            $this->directory = '';
            $ext = $this->config->item('controller_suffix').EXT;
            
            /* use module route if available */
            if (isset($segments[0]) AND $routes = Modules::parse_routes($segments[0], implode('/', $segments))) {
                $segments = $routes;
            }
            
            /**
            *    edit to route the administrative controllers
            *    without needing to go through the uri module/admin/module
            *    if the 1st segment is the administrative directory mask automatically routes to the 
            *    administrative controller
            */
            if($segments[0] == $this->config->item('admin_dir_mask'))
            {
                $segments[0] = $this->config->item('admin_dir');
                $module = $segments[1];
                array_unshift($segments,$module);
            }
            /* get the segments array elements */
            list($module, $directory, $controller) = array_pad($segments, 3, NULL);
    
            /* check modules */
            foreach (Modules::$locations as $location => $offset) {
            
                /* module exists? */
                if (is_dir($source = $location.$module.'/controllers/')) {
                    
                    $this->module = $module;
                    $this->directory = $offset.$module.'/controllers/';
                    
                    /* module sub-controller exists? */
                    if($directory AND is_file($source.$directory.$ext)) {
                        return array_slice($segments, 1);
                    }
                        
                    /* module sub-directory exists? */
                    if($directory AND is_dir($source.$directory.'/')) {
    
                        $source = $source.$directory.'/'; 
                        $this->directory .= $directory.'/';
    
                        /* module sub-directory controller exists? */
                        if(is_file($source.$directory.$ext)) {
                            return array_slice($segments, 1);
                        }
                    
                        /* module sub-directory sub-controller exists? */
                        if($controller AND is_file($source.$controller.$ext))    {
                            return array_slice($segments, 2);
                        }
                    }
                    
                    /* module controller exists? */            
                    if(is_file($source.$module.$ext)) {
                        return $segments;
                    }
                }
            }
            
            /* application controller exists? */            
            if (is_file(APPPATH.'controllers/'.$module.$ext)) {
                return $segments;
            }
            
            /* application sub-directory controller exists? */
            if($directory AND is_file(APPPATH.'controllers/'.$module.'/'.$directory.$ext)) {
                $this->directory = $module.'/';
                return array_slice($segments, 1);
            }
            
            /* application sub-directory default controller exists? */
            if (is_file(APPPATH.'controllers/'.$module.'/'.$this->default_controller.$ext)) {
                $this->directory = $module.'/';
                return array($this->default_controller);
            }
        }

    you would need to define 2 config items as you can see
    admin_dir_mask => this is the string you use in the uri to access administrative controllers
    admin_dir => this is where your administrative controllers will reside inside your module.controllers directory

    If you know a better way to do it, please post. I would be more than happy to implement them. 😊

  • #118 / Sep 16, 2011 7:57pm

    wiredesignz

    2882 posts

    @liri, Could you please post the error messages you are receiving, with line numbers please. It would be helpful to see what these are and where they are occurring.

  • #119 / Sep 17, 2011 10:25am

    liri

    50 posts

    @wire yep.

    Here it is:
    ERROR - 2011-09-16 17:24:03—> Severity: Notice —> Undefined property: Code::$_ci_classes /home/path_to_app/application/third_party/MX/Loader.php 266

  • #120 / Sep 17, 2011 8:52pm

    wiredesignz

    2882 posts

    @liri, The $_ci_classes variable is part of the CI_Loader class which is extended by MX_Loader, but for some reason MX_Loader is not able to access it in your application. The magic __get() method (line 266) in MX_Loader is then passing the call to the Code controller which causes the error.

    In a non-HMVC application (Controllers extend CI_Controller) this should not be occurring because the conroller is not registered to MX_Loader.

    In any case, even if CI_Loader::$_ci_classes is a protected class variable it does not prevent a class extension from accessing the variable internally and it should be available.

    I cannot duplicate this error. So I suggest you download and reinstall both CI 2.1.0-dev and HMVC 5.4

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

ExpressionEngine News!

#eecms, #events, #releases