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]
  • #226 / Feb 22, 2012 8:58pm

    Keat Liang

    29 posts

    Hi, wiredesignz i made some improvement on this function

    when routing error, or invalid URL, it will actually show the URL in the log file which may
    be very useful.

    hope you can add this in…

    on third_party/MX/Router.php

    public function _validate_request($segments) {
    
      if (count($segments) == 0) return $segments;
      
      /* locate module controller */
      if ($located = $this->locate($segments)) return $located;
      
      /* use a default 404_override controller */
      if (isset($this->routes['404_override']) AND $this->routes['404_override']) {
       $segments = explode('/', $this->routes['404_override']);
       if ($located = $this->locate($segments)) return $located;
      }
      
      /* no controller found */
      show_404(implode('/', $segments)); //little enhancement here <<-------
     }
  • #227 / Feb 23, 2012 8:19am

    Dan Tdr

    20 posts

    Hello, i had a problem and needed to load by default a controller with a different name than the module.
    All my modules had plural names (modules, clients, projects, examples), i was using gas orm and i had the same table names (plural) as module names and gas orm needed to have the module class the same as the database tables, so if i wanted to have a controller called clients in my clients module it would get in conflict with the clients model. So i wanted to be able to load a different controller by default, i thought that a simple takedown of this problem would be to make it so the modules keep their plural names and the controllers to be put at singular. I did not change the default functionality if you would have a module projects, with a controller projects it would load it by default even if you had another controller project, but, if you had a module projects and a controller project, with the code below, it would first search for the controller with the same name as the module and if not found, it would search for the singular name controller and load it ( so that you would not have to type projects/project to access it, or use routes for every module you have)

    the code is:
    on third_party/MX/Router.php or libraries/MX/Router.php under line 122 add

    /* module singular controller exists? edit dantdr */   
        if(is_file($source.substr($module, 0, -1).$ext)) {
         $segments[0] = substr($module, 0, -1);
         return $segments;
         
        }

    this makes it work, but is there a better way to do this? and if it is, could it be added to the next version of Modular Extension?

  • #228 / Mar 14, 2012 4:10pm

    douweegbertje

    13 posts

    First of all thanks for all your work.

    Second I would like to know if I’m actually understanding this correctly how to work with HMVC.

    Lets say I have ion auth, and I’m using this in my CMS module:

    <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
    
    class Cms extends MX_Controller {
     
     public function __construct()
     {
      $this->load->module('auth'); // loading auth. module
     }
     
     public function index()
     {
      if ($this->ion_auth->logged_in()) // check if you are logged in
      {
       echo "you are logged in";
      }
      else 
      {
       echo "you are not logged in";
      }
     }
    }

    Am I actually using HMVC the correct way at this point?

    Thanks

  • #229 / Mar 14, 2012 6:40pm

    shinokada

    144 posts

    I read http://ellislab.com/forums/viewthread/92212/P510/#969568 how to use form_validation in a controller. But how can I use it in a library? It seems not working with the following.

    class Auth_form_processing
    {
        public $CI;
        
     function __construct()
     {
          $this->CI->load->library('form_validation');
          $this->form_validation->CI =& $this;
            ....
     }

    Thanks for your help.

  • #230 / Mar 23, 2012 5:29am

    Keat Liang

    29 posts

    i have new suggestion @wiredesignz !

    based on the latest code Loader.php
    ORIGINAL

    /** Initialize the loader variables **/
     public function initialize($controller = NULL) {
      
      if (is_a($controller, 'MX_Controller')) { 
       
       /* reference to the module controller */
       $this->controller = $controller;
       
       /* references to ci loader variables */
       foreach (get_class_vars('CI_Loader') as $var => $val) {
        if ($var != '_ci_ob_level') {
         $this->$var =& CI::$APP->load->$var;
        }
       }
       
      } else {
       parent::initialize();
      }
    
      /* set the module name */
      $this->_module = CI::$APP->router->fetch_module();
      
      /* add this module path to the loader variables */
      $this->_add_module_paths($this->_module);
     }

    change to this

    /** Initialize the loader variables **/
     public function initialize($controller = NULL) {
      
      if (is_subclass_of($controller, 'MX_Controller')) { // in case there is exteded controller like mine
       
       /* reference to the module controller */
       $this->controller = $controller;
       
       /* references to ci loader variables */
       foreach (get_class_vars('CI_Loader') as $var => $val) {
        if ($var != '_ci_ob_level') {
         $this->$var =& CI::$APP->load->$var;
        }
       }
       
      } else {
       parent::initialize();
      }
    
      /* set the module name */
      $this->_module = CI::$APP->router->fetch_module();
      
      /* add this module path to the loader variables */
      $this->_add_module_paths($this->_module);
     }

    and also check it out another enhancement i suggest
    http://ellislab.com/forums/viewreply/981841/

  • #231 / Mar 23, 2012 6:35am

    wiredesignz

    2882 posts

    @Keat Liang,

    1.) The two PHP functions give the same result in this context.

    is_a — Checks if the object is of this class or has this class as one of its parents

    is_subclass_of — Checks if the object has this class as one of its parents

    Visit: http://php.net

    2.)
    You are free to extend the MX_Router class as you wish. Simply add your code to the empty MY_Router class extension.

  • #232 / Apr 04, 2012 1:30pm

    inc

    7 posts

    hi wiredesignz,

    thank you for hmvc library. it is really great, but i need your assistance. i have a structure like this:

    application/modules/institutions/controllers/admin/*
    application/modules/institutions/controllers/member/*
    application/modules/organizations/controllers/admin/*
    application/modules/organizations/controllers/member/*
    application/modules/users/controllers/admin/*
    application/modules/users/controllers/member/*

    module users wants to display some content of institutions and organizations. so:

    echo Module::run(‘institutions/admin/institutions/get_view’);
    echo Module::run(‘organizations/admin/organizations/get_view’);

    and everything will be fine. but if you have the same controller name in different modules it won’t.

    echo Module::run(‘institutions/admin/institutions/get_view’);
    echo Module::run(‘organizations/admin/institutions/get_view’);

    it will display the content of first initiated - in this case institutions. but if you make a hack like this:

    echo Module::run(‘institutions/admin/institutions/get_view’);
    echo Module::run(‘organizations/admin/somenameanythingyouwant/get_view’);

    it will work like supposed to. the problem is with Modules.php file LINE 85:

    $alias = strtolower(basename($module));

    alias is defined by last “dir” entry. i think the problem would exist even if i don’t have such a complex structure, because once loaded controller’s class name will always stay in registry even if it comes from a different module.

    can you suggest me a workaround please? i will have duplicate controller names in a structure… thank you very much.

  • #233 / Apr 04, 2012 5:14pm

    wiredesignz

    2882 posts

    This problem has nothing to do with Modular Extensions HMVC.

    PHP does not allow objects with duplicate class names to exist in the same namespace.

    The workaround is not to have duplicate class names.

  • #234 / Apr 04, 2012 6:38pm

    inc

    7 posts

    well yes, i knew that, but don’t you think if you’re running (not loading for later use) something it should be properly executed without the impact of environment?

    this could be done by recognizing from which module a class is requested or you can run something, execute it (some random temp name) and at the end destroy it. this way, run and load will have much more different meaning and use.

    the code line i’ve mentioned makes a name alias with basename function which returns the trailing name of the whole path. so if you have a controller’s subdir structure like i have, and obviously i will have admin and member sections in all modules, i cannot run a module like this: (controller name is the same as module_name)

    Modules::run(‘module_name1/subdir/method’);
    Modules::run(‘module_name2/subdir/method’);

    because instance will be named in both cases as ‘subdir’ which is not true.

  • #235 / Apr 05, 2012 2:34am

    wiredesignz

    2882 posts

    well yes, i knew that, don’t you think if you’re running (not loading for later use) something it should be properly executed without the impact of environment?

    this could be done by recognizing from which module a class is requested or you can run something, execute it (some random temp name) and at the end destroy it. this way, run and load will have much more different meaning and use…

    You obviously do not understand that while you may be able to destroy objects, you cannot (yet) unload classes.

  • #236 / Apr 05, 2012 4:01am

    Tsuki Kamui

    1 posts

    hi, i have question for the hmvc~

    There is a not found error from log, when i created a public_controller.php in core folder.
    Then, I used it extends MY_controller.

    example:
    ./core
    —>MY_Controller.php
    —>Public_Controller.php

    ./modules
    -./example
    —./controllers
    —-./example.php

    class example extends Public_Controller{
    ...
    }

    Then, the 404 not found error would be logged.
    when i remove the public_controller.php
    then, the controller extends “MY_controller”
    The 404 not found error would be gone away.~

    plz help~~
    thx!!!

     

  • #237 / Apr 05, 2012 4:35am

    inc

    7 posts

    You obviously do not understand that while you may be able to destroy objects, you cannot (yet) unload classes.

    “execute it (some random temp name)”. you can assign any name you want right? i mean you’re already doing it. i cannot see anything bad with it. correct me if i’m wrong.

    module: organizations.
    controller: organizations.
    subdir: admin

    Modules::run(‘organizations/admin/get’); -> will produce class name Admin.

  • #238 / Apr 05, 2012 4:52am

    wiredesignz

    2882 posts

    @inc, Class names can not be customized at run time.

    You appear to be confusing assignable object names with class names.

  • #239 / Apr 12, 2012 9:14am

    inc

    7 posts

    @inc, Class names can not be customized at run time.

    You appear to be confusing assignable object names with class names.

    yep, this was my problem and i was confused by that. feeling like a newbie right now 😊 sorry about that.

    but i have a new question:

    i wanted to load a rest library with different object name. i did it like this:
    $this->load->library(‘rest’, FALSE, ‘rest1’);
    $this->load->library(‘rest’, FALSE, ‘rest2’);

    but it doesn’t create an rest2 object.

    i think the problem is in Loader.php file LINE 139.

  • #240 / Apr 22, 2012 10:14am

    Tench

    1 posts

    When installing HMVC, is the provided MY_Loader.php supposed to completely replace the existing MY_Loader.php in application/core?

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

ExpressionEngine News!

#eecms, #events, #releases