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.

HMVC problem loading views

November 11, 2010 7:20am

Subscribe [6]
  • #1 / Nov 11, 2010 7:20am

    Davcon

    110 posts

    Hi,

    I’ve recently got into HMVC and I’ve ran into a problem.

    I’m trying to create an HMVC application that uses two modules - “messages” and “users”.


    If I go to *THE_BASE_URL*/users/chooseorg (to test the users module), everything works fine.  So, it reads the view file and functions perfectly. (no module vibes in use so far)

    The trouble is, if I call that same users module from within the “messages” module the I get a “Unable to locate the file: sayhello.php” error.

    This problem is killing me.

    Here’s my code for calling the users module.  The code below would be in a VIEW file, within the messages module:

    <h1>Create a New Lead</h1>
    Please select a lead source and then press 'Submit'
    <?php 
    modules::run('users/chooseorg');  
    ?>


    ...and here is the choose org method that’s on the users module:

    function chooseorg() {       
            $this->load->view('sayhello');           
    }

      (note: the view file just says print ‘hello world’ (for testing)

  • #2 / Nov 11, 2010 7:30am

    wiredesignz

    2882 posts

    Using modules::run(), the controller must extend MX_Controller to identify which module to load the view from. Otherwise you must prefix the view with its module name.

  • #3 / Nov 11, 2010 7:32am

    Davcon

    110 posts

    Hi,

    Thanks for your reply.  I understand what you mean about prefixing the view.  However, I’d be very grateful if you could clarify what you meant on the first part of your response (or perhaps send me to a link where I can read up).

    Many thanks.

  • #4 / Nov 11, 2010 7:45am

    wiredesignz

    2882 posts

    There is already a link in my signature.

    If you use HMVC features then controllers must extend MX_Controller.

  • #5 / Nov 11, 2010 7:56am

    Davcon

    110 posts

    Wow!

    I just realised, you’re the guy who invented the HMVC thing for Codeigniter.  Gee!  I’m slightly overwhelmed here.  What an honour!  Thanks so much for giving me your time.

    Look, I’m a complete peasant when it comes to all of this stuff. 

    When your second reply come in I was actually (by the sheerist of coincidences) reading the very page that’s on your link.

    The challenge I have is that your page doesn’t specifically mention how to extend the MX controller (unless I’m very much mistaken).  So, it doesn’t give you the code for extending the MX controller nor does it say where that code should go.

    Now, I know I’m being a pain here and I’m asking you to spoon feed me.  I’m sorry for that.  However, if you could please take a moment to spoon feed me out of this mess then I’ll donate 50 dollars to your cause via Paypal, the moment I’ve got it working.

    Does that sound like a fair deal?

  • #6 / Nov 11, 2010 8:03am

    wiredesignz

    2882 posts

    Don’t go overboard, it’s pretty easy.

    class Users extends MX_Controller 
    {
        function chooseorg()
        {
    
        }
    }
  • #7 / Nov 11, 2010 8:15am

    Davcon

    110 posts

    Hi,

    It might be easy for you but I’m afraid it’s not so easy for me.  I’m getting the following error:

    Fatal error: Cannot redeclare class CI in C:\wamp\www\hmvctest\system\application\third_party\MX\Base.php on line 76


    My code for the user controller is

    <?php
    class Users extends MX_Controller {
        
        function Users() {
            parent::Controller();
            $this->load->library('drawusers');
            $this->load->library('drawpageadmin');
        }
        
    
    
    
        function chooseorg() {       
            $this->load->view('sayhello');       
        }


    My code for the other controller does NOT do the MX extention. I hope I’ve got that right.


    * getting this working will be the highlight of the week for me and I’m looking forward to donating the moment it’s working *

  • #8 / Nov 11, 2010 8:23am

    wiredesignz

    2882 posts

    Use PHP5 coding conventions.

    <?php
    class Users extends MX_Controller 
    {
        function __construct() 
        {
            parent::__construct();
            $this->load->library(array('drawusers', 'drawpageadmin'));
        }
    
        function chooseorg() 
        {       
            $this->load->view('sayhello');       
        }  
    }
  • #9 / Nov 11, 2010 11:09am

    Davcon

    110 posts

    Well, I’m not getting an error message now and I feel that I’m making progress.

    The only trouble I have now is that the view file (sayhello) is not displaying.  The view file’s code is simply this:

    <?php
    print "hello there";
    ?>


    That view is being called from the other module which is called ‘users’ but it’s not displaying.  Strangly enough, if I kill the script and say ‘die()’ immediately after the print ‘hello there’, then the hello message does appear - but only as part of a half-loaded, broken page.


    By the way, I’ve just sent you fifty dollars as a way of saying thank you for your help with this.  I really appreciate it.

  • #10 / Nov 11, 2010 5:02pm

    wiredesignz

    2882 posts

    Thank you. Your donation is much appreciated.

  • #11 / Dec 05, 2010 7:54pm

    Timothy_

    100 posts

    Hello,

    Was this issue ever resolved?

    I am having the same problem. If I view the module at it’s URL http://domain.com/controller then the view shows correctly.

    However adding

    <?php echo modules::run('controller'); ?>
    or
    <?php echo modules::run('module/controller'); ?>

    in one of my views causes the page to stop rendering at the point I have called the view partial.

    Does anyone have any idea on how I can fix or at the very least debug this?

    Thanks,

    Tim

  • #12 / Dec 07, 2010 12:13am

    Timothy_

    100 posts

    To add a little more info to my above question.

    The problem is when I place

    <?php echo modules::run('controller'); ?>

    in my view the page stops executing at that point and does not output anything below that call.

    1. I am extending MX_Contoller in my controllers that my modules are calling and no errors are showing to show me otherwise.

    2. When I don’t extend MX_Controller it errors in the way I would expect it to, however the page still stops executing at that point.

    3. If I don’t reference any external libraries like session or ion_auth everything works fine and the view is output from the module.

    Please help.

    I really need to get something like this working.

    Thanks,

    Tim

  • #13 / Dec 07, 2010 4:20am

    wiredesignz

    2882 posts

    @Timothy_, Post your module/controller and view code.

  • #14 / Dec 07, 2010 6:08pm

    Timothy_

    100 posts

    @Timothy_, Post your module/controller and view code.

    No worries

    Module Controller `invoices`

    class Invoices extends MX_Controller {
    
    
           function __construct()
        {
            parent::__construct();
        }
       
        function index()
        {
        
        $user_id = $this->session->userdata('user_id');
        echo $user_id;
    
        }

    View Partial in view file

    Now you see me
    <?php echo modules::run('invoices'); ?>
    Now you don't

    Everything below the view partial call does not render.

    The session library is auto loaded in the application/config/autoload.php file and works fine for normal application controllers.

    As I have said, removing the extension from MX_Controller to Controller gets the View Partial to start working correctly… that is until you reference an external library like session or ion_auth.

    Thanks,

    Tim

    PS. I should also mention everything always works correctly when you trigger the controller normally at http://domain.com/invoices

  • #15 / Dec 08, 2010 4:29am

    wiredesignz

    2882 posts

    This code works without error on my installation here using CI 2.0 and MX 5.3.5

    modules/invoices/controllers/invoices.php

    <?php
    
    class Invoices extends MX_Controller {
        
        function index()
        {
            $user_id = $this->session->userdata('user_id');
            echo 'user id: ', $user_id;
        }
    }

    add to any view

    <?php echo modules::run('invoices'); ?>
.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases