32

HMVC : https://bitbucket.org/wiredesignz/codeigniter-modular-extensions-hmvc/downloads

After downloading CI and copying over the HMVC, I'm getting the following error:

An uncaught Exception was encountered

Type: Error

Message: Call to undefined method MY_Loader::_ci_object_to_array()

Filename: /Users/k1ut2/Sites/nine.dev/application/third_party/MX/Loader.php

Line Number: 300

Backtrace:

File: /Users/k1ut2/Sites/nine.dev/application/controllers/Welcome.php Line: 23 Function: view

File: /Users/k1ut2/Sites/nine.dev/index.php Line: 315 Function: require_once

5
  • You need create it in application > modules > your_module > controllers > Welcome.php Commented Jan 9, 2017 at 22:12
  • Old but good tutorial youtube.com/watch?v=8fy8E_C5_qQ Commented Jan 9, 2017 at 22:13
  • I did create it correctly, if the original Welcome file is eliminated the same error is returned Commented Jan 9, 2017 at 22:13
  • File: /Users/k1ut2/Sites/nine.dev/application/controllers/Welcome.php Line: 23 Function: view this in error Commented Jan 9, 2017 at 22:14
  • Try yourself, download the latest and include HMVC. I've created the files, just forgot to delete the old ones. But after deletion the same error is returned. I even renamed the view required and function in the controller and no success Commented Jan 9, 2017 at 22:19

5 Answers 5

111

Just adding this here as the Link provided by Clasyk isn't currently working...

The short version from that thread boils down to this...

In application/third_party/MX/Loader.php you can do the following...

Under public function view($view, $vars = array(), $return = FALSE) Look for... (Line 300)

return $this->_ci_load(array('_ci_view' => $view, '_ci_vars' => $this->_ci_object_to_array($vars), '_ci_return' => $return));

Replace this with

if (method_exists($this, '_ci_object_to_array'))
{
        return $this->_ci_load(array('_ci_view' => $view, '_ci_vars' => $this->_ci_object_to_array($vars), '_ci_return' => $return));
} else {
        return $this->_ci_load(array('_ci_view' => $view, '_ci_vars' => $this->_ci_prepare_view_vars($vars), '_ci_return' => $return));
}

It's the result of a "little" undocumented change that the CI Devs implemented, which is fine!

There is a pull request on Wiredesignz awaiting action so he knows about it...

In the meantime, you can implement the above "diddle" and get back to coding :)

Sign up to request clarification or add additional context in comments.

4 Comments

Your if() is missing the underscore - should be _ci_object_to_array
sneaky undocumented feature... thanks for the quick fix code, saved me some debug time.
wow, great solution. I was face same problem. Now my system is ok.
Turning to warn that the problem persists to this day, in Wiredesignz did not pull request of this correction.
5

I got the solution.this is working for me. On Line 300 of application/third_party/MX/Loader.php

This line generates an error with CI 3.1.3

return $this->_ci_load(array('_ci_view' => $view, '_ci_vars' => $this->_ci_object_to_array($vars), '_ci_return' => $return));

Replace with this line.

return $this->_ci_load(array('_ci_view' => $view, '_ci_vars' => $this->_ci_prepare_view_vars($vars), '_ci_return' => $return));
}

Comments

4

Found this Use this place in application / core / MY_Loader.php

From here https://bitbucket.org/wiredesignz/codeigniter-modular-extensions-hmvc/pull-requests/17/fix-loaderphp-for-ci-313/diff#comment-30560940

<?php (defined('BASEPATH')) OR exit('No direct script access allowed');

/* load the MX_Loader class */
require APPPATH."third_party/MX/Loader.php";

class MY_Loader extends MX_Loader
{
    /** Load a module view **/
    public function view($view, $vars = array(), $return = FALSE)
    {
        list($path, $_view) = Modules::find($view, $this->_module, 'views/');

        if ($path != FALSE)
        {
            $this->_ci_view_paths = array($path => TRUE) + $this->_ci_view_paths;
            $view = $_view;
        }

        return $this->_ci_load(array('_ci_view' => $view, '_ci_vars' => ((method_exists($this,'_ci_object_to_array')) ? $this->_ci_object_to_array($vars) : $this->_ci_prepare_view_vars($vars)), '_ci_return' => $return));
    }
}

Comments

3

HMVC doesn't work with 3.1.3 (current version). But works with all versions up to 3.1.2. Just tested this myself from 3.0.0 upwards.

3 Comments

Good point I have now asked on the codeigniter forum. I tested it out you are right.
As pointed in the forum link, changing $this->_ci_object_to_array($vars) to $this->_ci_prepare_view_vars($vars) in "application\third_party\MX\Loader.php" on line 300 worked. Thanks
Somehow the error is there on 3.1.11. Along with strpos() error on line 239 (MX/Router.php)
1

Add this lines in application/third_party/MX/Loader.php after line 307,

protected function _ci_object_to_array($object) 
	{
    return is_object($object) ? get_object_vars($object) : $object;
    }

However for 3.1.3 HMVC doesn't work.

better luck.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.