php CodeIgniter HMVC object_to_array() 错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/41557760/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
CodeIgniter HMVC object_to_array() error
提问by whisky
HMVC : https://bitbucket.org/wiredesignz/codeigniter-modular-extensions-hmvc/downloads
HMVC:https: //bitbucket.org/wiredesignz/codeigniter-modular-extensions-hmvc/downloads
After downloading CI and copying over the HMVC, I'm getting the following error:
下载 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
遇到未捕获的异常
类型:错误
消息:调用未定义的方法 MY_Loader::_ci_object_to_array()
文件名:/Users/k1ut2/Sites/nine.dev/application/third_party/MX/Loader.php
行号:300
回溯:
文件:/Users/k1ut2/Sites/nine.dev/application/controllers/Welcome.php 行:23 功能:查看
文件:/Users/k1ut2/Sites/nine.dev/index.php 行:315 功能:require_once
回答by TimBrownlaw
Just adding this here as the Link provided by Clasyk isn't currently working...
只需在此处添加此内容,因为 Clasyk 提供的链接目前无法正常工作...
The short version from that thread boils down to this...
该线程的简短版本归结为...
In application/third_party/MX/Loader.php you can do the following...
在 application/third_party/MX/Loader.php 您可以执行以下操作...
Under public function view($view, $vars = array(), $return = FALSE)
Look for... (Line 300)
在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));
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!
这是 CI 开发人员实施的“小”未记录更改的结果,这很好!
There is a pull request on Wiredesignz awaiting action so he knows about it...
Wiredesignz 上有一个 pull request 正在等待行动,所以他知道这件事......
In the meantime, you can implement the above "diddle" and get back to coding :)
同时,您可以实现上面的“diddle”并返回编码:)
回答by Muhammad Zaman
I got the solution.this is working for me. On Line 300 of application/third_party/MX/Loader.php
我得到了解决方案。这对我有用。在 application/third_party/MX/Loader.php 的第 300 行
This line generates an error with CI 3.1.3
此行在 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));
}
回答by Mr. ED
Found this Use this place in application / core / MY_Loader.php
发现这个 Use this place in application/core/MY_Loader.php
<?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));
}
}
回答by whisky
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.
HMVC 不适用于 3.1.3(当前版本)。但适用于高达 3.1.2 的所有版本。刚刚从 3.0.0 开始自己测试了这个。
回答by Ganga
Add this lines in application/third_party/MX/Loader.php after line 307,
在 application/third_party/MX/Loader.php 的第 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.
但是对于 3.1.3 HMVC 不起作用。
better luck.
好运。