Welcome Guest, Not a member yet? Register   Sign In
HMVC problem loading views
#1

[eluser]Davcon[/eluser]
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:

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


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

Code:
function chooseorg() {      
        $this->load->view('sayhello');          
}
(note: the view file just says print 'hello world' (for testing)
#2

[eluser]wiredesignz[/eluser]
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

[eluser]Davcon[/eluser]
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

[eluser]wiredesignz[/eluser]
There is already a link in my signature.

If you use HMVC features then controllers must extend MX_Controller.
#5

[eluser]Davcon[/eluser]
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

[eluser]wiredesignz[/eluser]
Don't go overboard, it's pretty easy.
Code:
class Users extends MX_Controller
{
    function chooseorg()
    {

    }
}
#7

[eluser]Davcon[/eluser]
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

Code:
&lt;?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

[eluser]wiredesignz[/eluser]
Use PHP5 coding conventions.
Code:
&lt;?php
class Users extends MX_Controller
{
    function __construct()
    {
        parent::__construct();
        $this->load->library(array('drawusers', 'drawpageadmin'));
    }

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

[eluser]Davcon[/eluser]
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:

Code:
&lt;?php
print "hello there";
?&gt;


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

[eluser]wiredesignz[/eluser]
Thank you. Your donation is much appreciated.




Theme © iAndrew 2016 - Forum software by © MyBB