CodeIgniter HMVC object_to_array() error

微笑、不失礼 提交于 2019-12-20 08:35:45

问题


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


回答1:


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




回答2:


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));
}



回答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.




回答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));
    }
}



回答5:


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.



来源:https://stackoverflow.com/questions/41557760/codeigniter-hmvc-object-to-array-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!