【问题标题】:CodeIgniter HMVC object_to_array() errorCodeIgniter HMVC object_to_array() 错误
【发布时间】:2017-05-24 06:56:24
【问题描述】:

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

下载 CI 并通过 HMVC 复制后,我收到以下错误:

遇到未捕获的异常

类型:错误

消息:调用未定义的方法 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 功能: 需要一次

【问题讨论】:

  • 你需要在application > modules > your_module > controllers > Welcome.php 创建它
  • 我确实正确创建了它,如果删除了原始欢迎文件,则会返回相同的错误
  • File: /Users/k1ut2/Sites/nine.dev/application/controllers/Welcome.php Line: 23 Function: view 出错
  • 试试自己,下载最新版本并包含 HMVC。我已经创建了文件,只是忘记删除旧文件。但删除后返回相同的错误。我什至重命名了控制器中所需的视图和功能,但没有成功

标签: php codeigniter hmvc-codeigniter


【解决方案1】:

只需在此处添加此内容,因为 Clasyk 提供的链接当前不起作用...

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

在 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 开发人员实施的“小”未记录更改的结果,这很好!

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

与此同时,您可以实现上述“diddle”并返回编码:)

【讨论】:

  • 您的 if() 缺少下划线 - 应该是 _ci_object_to_array
  • 偷偷摸摸的未记录功能...感谢快速修复代码,为我节省了一些调试时间。
  • 非常好的解决方案。为我工作。谢谢
  • 哇,很棒的解决方案。我面临同样的问题。现在我的系统没问题。
  • 转向警告问题一直存在到今天,在 Wiredesignz 中没有拉取此更正的请求。
【解决方案2】:

我得到了解决方案。这对我有用。 在 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));
}

【讨论】:

    【解决方案3】:

    找到这个在application/core/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));
        }
    }
    

    【讨论】:

      【解决方案4】:

      HMVC 不适用于 3.1.3(当前版本)。但适用于最高 3.1.2 的所有版本。刚刚从 3.0.0 开始自己测试。

      【讨论】:

      • 好点我现在在 codeigniter 论坛上问过了。我测试了你是对的。
      • 正如论坛链接中所指出的,在第 300 行的“application\third_party\MX\Loader.php”中将 $this-&gt;_ci_object_to_array($vars) 更改为 $this-&gt;_ci_prepare_view_vars($vars) 有效。谢谢
      • 3.1.11 上不知何故出现了错误。连同第 239 行 (MX/Router.php) 上的 strpos() 错误
      【解决方案5】:

      在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 不起作用。

      祝你好运。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2016-03-09
        • 2017-12-10
        • 1970-01-01
        • 2016-02-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多