Welcome Guest, Not a member yet? Register   Sign In
CI 3 & HMVC Issue
#1

Ok so i have HMVC up and running (Mostly).  All the features work except for calling my controller form a controller.... I can access the different controllers directly by module/controller/method or simply module/method that all works.  I can process information through one of the controllers.  I can't access one controller from the other and vice versa...

I have tried 


PHP Code:
$this->load->module('payment');
$result_data $this->Payment->process_payment($submitted_data); 

Also tried this one
PHP Code:
$result_data $this->load->module('Payment')->process_payment($submitted_data); 

All resulting in "Fatal error: Call to a member function process_payment() on a non-object"


I have tried everything and everything else seems to work.  no 404's nothing.  I am at a loss to figure out what might be wrong.  The only thing I didn't do was setup routs in the modules but did not thing that was needed, just one more thing to keep track of if it is not needed.


Any help would be greatly appreciated.  This is the first CI3 & HMVC app for me so I am not sure where to look next.


Thanks
Reply
#2

OK as I am working on this further I have been debugging and it looks like the Payments module is being found and loaded fine. Well As fine as I can tell. I follow the code all the way through MX loader, modules and router class and everything works and it sees the module and class.

It is when I make this call $result_data = $this->Payment->process_payment($submitted_data); that the code goes right to return CI::$APP->$class; in the controller class and right to the error handler.

Now as I stop at that point I can't seem to navigate through the $CI to see the loaded classes. Maybe I could not in the past but thought I could. So it seems like HMVC is not loading the class correctly? This is just a guess at this moment.

Should I be able to debug and see all the loaded modules that you load via the $this->load->xxxx?
Reply
#3

Here is another version of the error if this could help.

A PHP Error was encountered

Severity: Notice
Message: Undefined property: CI::$Payment
Filename: MX/Controller.php
Line Number: 59
Backtrace:
File: /Applications/MAMP/htdocs/ezolp/application/third_party/MX/Controller.php
Line: 59
Function: _error_handler
File: /Applications/MAMP/htdocs/ezolp/application/modules/guestform/controllers/Guestform.php
Line: 87
Function: __get
File: /Applications/MAMP/htdocs/ezolp/index.php
Line: 292
Function: require_once   
Reply
#4

Also just made sure i had the latest code that supported CI3.
Reply
#5

So in doing more research this turns out to be just an issue with case.  I am not sure if as I changed it back and forth if there was some Apache caching that was causing issue or what.  Also I don't think it is correct the way the call is being made but I am not an expert.

Module Setup
- Modules
--- payment
------ controllers
---------Payment.php

Code in the controller is

PHP Code:
<?php
class Payment extends MX_Controller
{
 
   public function process_payment()
 
   {
 
       .....
 
   }



So now I load the Module
PHP Code:
$this->load->module('payment'); 

Then I call the module
PHP Code:
$this->Payment->process_payment(); 

Now the above call does not work even though it matches the case and signature of the class.  And I have other classes setup the exact same way and they are working perfectly fine.  The call to this class will not work as an upper case call "Payment".

So I change that line to this
PHP Code:
$this->payment->process_payment(); 
And it is working fine.

This seems wrong to me, can anyone else explain why I would have one class that can be called either way upper or lower and one class that does not work at all that way?

It should either work or not work, and maybe it does but I have something screwed up somewhere.

Anyway I can keep going and hit my due date but this cost me several hours and really don't have an explanation. 
Reply
#6

Still have a question about the upper vs lower case issue.  But also found this handy code to make sure that Apache is not caching the pages.....  Place this in the .htaccess file and it should lower confusion while making changes...

Code:
<filesMatch "\.(html|htm|js|css)$">
 FileETag None
 <ifModule mod_headers.c>
    Header unset ETag
    Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
    Header set Pragma "no-cache"
    Header set Expires "Wed, 11 Jan 1984 05:00:00 GMT"
 </ifModule>
</filesMatch>
Reply
#7

(This post was last modified: 04-17-2015, 02:04 PM by mwhitney. Edit Reason: remove smiley )

If you look in the MX/Loader and find the module() method (which is called when you use $this->load->module(); ) you'll see something like this:


PHP Code:
    /** Load a module controller **/
    
public function module($module$params NULL)    
    {
        if (
is_array($module)) return $this->modules($module);

        
$_alias strtolower(basename($module));
        
CI::$APP->$_alias Modules::load(array($module => $params));
        return 
$this;
    } 

To explain this code a little, assume that CI::$APP is going to be $this in your calling method, and as we see in the line above it, $_alias is the lowercase name of your module. So the loader loads the controller for your module and places the controller instance into CI::$APP->$_alias, so you can access the controller instance from $this->lowercase_name_of_your_module.

If you always pass lowercased strings to the loader, this behavior is actually very consistent with a standard CI installation. Almost anything you load becomes available on $this->lowercase_name_of_loaded_class, with the most common exception being helpers, which don't normally contain classes anyway.
Reply
#8

HMVC is just following the default CI behavior. It uses strtolower for libraries, models, etc as well. See system/core/Loader.php
Reply
#9

I made a little change in the MX Loader and it worked.

/** Load a module model **/
public function model($model, $object_name = NULL, $connect = FALSE)
{
if (is_array($model)) return $this->models($model);

($_alias = $object_name) OR $_alias = basename($model);

if (in_array($_alias, $this->_ci_models, TRUE))
return $this;

/* check module */
// this-> list($path, $_model) = Modules::find(strtolower($model), $this->_module, 'models/');
list($path, $_model) = Modules::find($model, $this->_module, 'models/');
Reply




Theme © iAndrew 2016 - Forum software by © MyBB