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

Pradeep
  • 9,667
  • 13
  • 27
  • 34
whisky
  • 533
  • 1
  • 6
  • 14
  • You need create it in `application > modules > your_module > controllers > Welcome.php ` –  Jan 09 '17 at 22:12
  • Old but good tutorial https://www.youtube.com/watch?v=8fy8E_C5_qQ –  Jan 09 '17 at 22:13
  • I did create it correctly, if the original Welcome file is eliminated the same error is returned – whisky Jan 09 '17 at 22:13
  • `File: /Users/k1ut2/Sites/nine.dev/application/controllers/Welcome.php Line: 23 Function: view` this in error –  Jan 09 '17 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 – whisky Jan 09 '17 at 22:19

5 Answers5

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 :)

TimBrownlaw
  • 5,457
  • 3
  • 24
  • 28
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));
}
Muhammad Zaman
  • 280
  • 4
  • 19
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));
    }
}
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.

whisky
  • 533
  • 1
  • 6
  • 14
  • 1
    Good point I have now asked on the codeigniter forum. I tested it out you are right. –  Jan 10 '17 at 00:11
  • 6
    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 – Barun Jan 26 '17 at 15:57
  • Somehow the error is there on 3.1.11. Along with strpos() error on line 239 (MX/Router.php) – Izzy Helianthus Oct 23 '19 at 22:19
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.

Ganga
  • 31
  • 4