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]
  • #316 / Jan 09, 2013 5:52am

    MainmanFR

    4 posts

    Hi, thanks for your reply. I resolve the problem with renaming. The module name and controller were apparently wrong ...

    I encountered an other problem : i use an internationalization system and I extend both MX_Lang and MX_Config.
    In the MX_Lang constructor I’ve got a :

    global $CFG;
    $CFG->load('language');

    and in MX/Config.php, i’ve got an error in the load fonction :

    Fatal error: Class 'CI' not found in /homez/..../application/third_party/MX/Config.php on line 42

    If I don’t extend Config, no problem. But I need to have a function i18n_url() similar to site_url() for rewrite URLs with language.

    Any help wery appreciated.
    Thanks in advance !

  • #317 / Jan 10, 2013 8:09am

    MainmanFR

    4 posts

    Thanks Dafreak !!!
    Exactly what I was looking for. Don’t know why HMVC team never do a thing like that ! I tell you if I encounter some problems.

    its a quick and dirty solution so any (constructive) comments are welcomed

  • #318 / Feb 06, 2013 2:58am

    Ts8060

    1 posts

    Hi wiredesignz. Thanks for great extension.
    But i have question.
    1. Can i use _output function in Controller that extended from MX_Controller.
    2. Can i create Core Controller Class in application/core. And i want to use Modules::run function from that class. How can i do that

  • #319 / Feb 18, 2013 10:05am

    seanloving

    120 posts

    I want to call Modules::run twice within the same controller but my second call cannot find the controller method in the module that I am targeting.

    For example

    function index() {
     // code
     $headerdata['loginbar'] = Modules::run('users/forms/login');
     $maindata['search'] = Modules::run('contacts/forms/search');
     //code
    }

    gives an error on the second call
    Call to undefined method Forms::search() in \application\modules\contacts\controllers\contacts.php

    If I don’t make the first call then the second call finds the module controller and returns the data (form) that I expect.

    Has this been discussed or observed by anyone or is this expected?
    Thanks

    SOLVED— the users module and the contacts module cannot have controllers with identical names (forms). See also this explanation

  • #320 / Mar 27, 2013 5:01pm

    Kobus M

    54 posts

    Hi Wiredesignz,

    Thanks again for the plugin. It generally works very well for me, but I am really struggling with routing inside my modules.

    I have routes like this in my main application/config/routes.php file

    $routes[‘login’] = ‘user/login’;

    So, when I go to site.com/login, I get the login screen defined in the user module.

    Moving this to /modules/user/config/routes.php does not work. No permutation of this in any way. I have tried:

    $routes[‘user’] = ‘user/login’;
    $routes[‘login’] = ‘user/login’;
    $routes[‘user/login’] = ‘user/login’;
    $routes[‘user’] = ‘user’; //index function calls login function, so site.com/user takes me to login.
    $routes[‘login’] = ‘user’;
    $routes[‘user/login’] = ‘user’;

    From the sources I could find, it seems like I have to use this kind of format:

    $routes[‘user’] = ‘user/login’;

    This does it work for me. I want to put the routes.php in my user module’s config directory, and go to site.com/login which will take me to site.com/user/login. I have done some checking and found that site.com/login is looking for a module called “login” which does not exist.

    I am getting a 404 error, regardless of which combination I try above.

    How can I make this work? Is this possible at all?

    Regards,

    Kobus

  • #321 / Apr 05, 2013 3:21am

    jsteinberg

    1 posts

    I recently had to do this so I thought I would post it in the hopes that someone can find it useful.

    My goal was to make all models within any modules autoload when instantiated (but not before) by tying into PHP’s spl_autoload functionality.  HMVC already uses this to autoload MX classes as well as core and library classes, so I just added to that.

    In the APP_ROOT/third_party/MX/Modules.php file you simply need to add the following to the autoload method which already exists there (the function starts on line 111).

    /* autoload module classes */
      $module_path = str_replace('/'.SYSDIR, '' ,BASEPATH)."application/modules/";
      if($dir = opendir($module_path))
      {
       while(false !== ($current_dir = readdir($dir)))
       {
        if(is_file($location = APPPATH.'modules/' . $current_dir . '/models/' . strtolower($class).EXT)){
         include_once $location;
         return;
        }
       }
      }

    This will work assuming your (relevant) directory layout is structured something like this (if your directory structure is slightly different, you can modify the paths/etc. in the above to match your case)

    / -
      - applications
        - modules
          - module_name
            - models
              - test_model.php
              - test2_model.php
          - module2_name
            - models
              - test_model.php

    The end result is that I can do something like this in my controllers without having to do any call of include_once/require_once or $this->load, etc. and the models are included automatically when I call them (rather than either all in the beginning using the autoload array or manually).

    // middle of some controller 
    function example() {
        // non-static method
        $test = new Test_Model();
        $test->do_something();
    
        // static method
        $test_data = Test2_Model::get_some_data();
    }

    Anyways, hope that helps someone.

  • #322 / Apr 16, 2013 7:43pm

    boytun

    30 posts

    Hello
    I get a big problem

    when I run the module from my main mvc view I get a probleme:

    A PHP Error was encountered
    Severity: Notice

    Message: Undefined property: Widg_html::$mdl_widg_html

    Filename: controllers/widg_html.php

    Line Number: 18


    Fatal error: Call to a member function get() on a non-object in C:\xampp\htdocs\application\modules\widg_html\controllers\widg_html.php on line 18

    but when I run it directly form the url(localhost/widg_html) it works fun.

    The name of my module is widg_html
    This is the controller of the module:

    <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
    
    class Widg_html extends MX_Controller {
    
     public function __construct()
     {
      parent::__construct();
    
      $this->load->model('mdl_widg_html_page');
      $this->load->model('mdl_widg_html_widget');
      $this->load->model('mdl_widg_html');
    }
    
     public function index()
     {
      $this->data['widget_body']=$this->mdl_widg_html->get();
      $this->load->view('display', $this->data[);
     }

    this is the model of the widget:

    <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
    
    class Mdl_widg_html extends CI_Model {
    
    public function __construct()
     {
      parent::__construct();
      
     }
    
     public function get(){
      return $this->db->get('widg_html');
     }
    
     public function get_by($where, $single = FALSE)  
     {
      $this->db->where($where);
      return $this->get(NULL, $single);
     }
    
    }

    and this is how I load the module into the mvc view through my controller page

    <?php echo Modules::run('widg_html') ; ?>

    Thanks in advance

  • #323 / Apr 17, 2013 3:50am

    wiredesignz

    2882 posts

    @boyfun,
    Line Number 18 of your Widg_html controller (as shown) has no code that can cause an error.

  • #324 / Apr 17, 2013 4:31am

    boytun

    30 posts

    so, from your experience, what is, approximately, the cause of the probleme.
    If you do not mind, I can send you a copy of my project.
    As you can see everything is clear, I spent more than week searching to solve this probleme.
    I am preparing my end of study project and the date of presentation will be very soon.
    Need your help, please save me :/

  • #325 / Apr 17, 2013 5:23am

    wiredesignz

    2882 posts

    ... I can send you a copy of my project…

    No thank you. I don’t want your code You need to keep working on it yourself.

  • #326 / Apr 17, 2013 5:38am

    boytun

    30 posts

    hhhhh,ok
    So, What do you think cause this problem ?

  • #327 / Apr 17, 2013 5:46am

    wiredesignz

    2882 posts

    @boyfun,

    I have already told you that the code you have posted does not relate to the error message you have provided.

  • #328 / Apr 18, 2013 9:10am

    boytun

    30 posts

    Hello

    In the mvc view I load my module like this
    <?php echo Modules::run(‘widg_html’) ; ?>
    but I get this error:

    A PHP Error was encountered
    Severity: Notice

    Message: Undefined property: Widg_html::$db

    Filename: models/mdl_widg_html.php

    Line Number: 12


    Fatal error: Call to a member function get() on a non-object in C:\xampp\htdocs\application\modules\widg_html\models\mdl_widg_html.php on line 12

    this is my module’s controller:

    class Widg_html extends MX_Controller {
    
     public function __construct()
     {
      parent::__construct();
    
      $this->load->model('mdl_widg_html');
    }
    
     public function index()
     {
       //$this->load->database();
      $data['widget_body']=Mdl_widg_html::get();
      $this->load->view('display',$data);
       //echo base_url(); 
     }
    }

    And this is my module’s model:

    <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
    
    class Mdl_widg_html extends CI_Model {
     public function __construct()
     {
      parent::__construct();
     }
    
     public function get()
     {
      
      return $this->db->get('widg_html');
     }
    
    }

    Please help me
    Thanks in advance

  • #329 / Apr 18, 2013 7:10pm

    boytun

    30 posts

    Hello
    I need to load my module into my application’s view, but I can’t.
    My module work fun if I excuted from localhost/mymodule, but if I call It from the view(echo Modules::run(‘mymodule’)) I get this:

    Cannot redeclare class CI in C:\xampp\htdocs\application\third_party\MX\Base.php on line 57
    application/
     + controllers/
        + main.php (extending Frontend_Controller)->load view display
     + core/
        + MY_Controller.php (extending CI_Controller) 
    +modules
        + mymodule
    +librairies
        +Frontend_Controller (extending MY_Controller) 
    +views
        +display

    Thanks in advance

  • #330 / Apr 19, 2013 2:40am

    wiredesignz

    2882 posts

    @boyfun,

    You need to learn about the difference between calling static methods in classes and calling methods in object context.

    Remember also, if you wish to use the HMVC features built into Modular Extensions HMVC then “all” of your controllers must extend the MX_Controller class.

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

ExpressionEngine News!

#eecms, #events, #releases