CodeIgniter HMVC object_to_array() 错误

CodeIgniter HMVC object_to_array() error

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

下载 CI 并复制 HMVC 后,出现以下错误:

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

HMVC 不适用于 3.1.3(当前版本)。但适用于 3.1.2 之前的所有版本。刚刚从 3.0.0 向上测试了这个。

由于 Clasyk 提供的 Link 当前无法正常工作,因此只需在此处添加此内容...

该线程的简短版本归结为...

在 application/third_party/MX/Loader.php 中,您可以执行以下操作...

public function view($view, $vars = array(), $return = FALSE)下寻找...(第300行)

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

将其替换为

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

这是 CI 开发人员实施的 "little" 未记录更改的结果,很好!

Wiredesignz 上有一个拉取请求正在等待操作,因此他知道了...

在此期间,您可以实施上述 "diddle" 并返回编码:)

在 application/third_party/MX/Loader.php 行 307 之后添加此行,

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

但是对于 3.1.3 HMVC 不起作用。

祝你好运。

找到这个在应用程序/核心/MY_Loader.php

中使用这个地方

从这里开始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));
    }
}

我知道 solution.this 对我有用。 在 application/third_party/MX/Loader.php

的第 300 行

此行生成错误 CI 3.1.3

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

替换为这一行。

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