Codeigniter 中的类错误对象与数组中的加载函数

1 codeigniter

在我的欢迎控制器上,我有一个名为的函数,在这种情况下content_top加载函数然后它应该在该数据数组中显示幻灯片函数视图。$this->$part[0]($setting_info);$this->slideshow($setting_info);

当我刷新页面时出现错误

A PHP Error was encountered
Severity: 4096
Message: Object of class CI_Loader could not be converted to string
Filename: common/content_top.php
Line Number: 7
Backtrace:
File: C:\wamp\www\cms\application\views\common\content_top.php
Line: 7
Function: _error_handler
File: C:\wamp\www\cms\application\controllers\Welcome.php
Line: 51
Function: view
File: C:\wamp\www\cms\application\controllers\Welcome.php
Line: 19
Function: content_top
File: C:\wamp\www\cms\index.php
Line: 292
Function: require_once
Run Code Online (Sandbox Code Playgroud)

A PHP Error was encountered
Severity: 4096
Message: Object of class CI_Loader could not be converted to string
Filename: common/welcome_message.php
Line Number: 3
Backtrace:
File: C:\wamp\www\cms\application\views\common\welcome_message.php
Line: 3
Function: _error_handler
File: C:\wamp\www\cms\application\controllers\Welcome.php
Line: 20
Function: view
File: C:\wamp\www\cms\index.php
Line: 292
Function: require_once
Run Code Online (Sandbox Code Playgroud)

问题 当我在数组中有一个函数时,有什么方法可以使其显示视图而不抛出错误。

<?php

class Welcome extends CI_Controller {

    public $data = array();

    public function __construct() {
        parent::__construct();
        $this->load->model('design/model_layout');
        $this->load->model('extension/model_module');
        $this->load->model('design/model_banner');
        $this->load->model('tool/model_image');

        $this->load->library('image_lib');
    }

    public function index() {
        $this->load->view('common/header');
        $data['content_top'] = $this->content_top();
        $this->load->view('common/welcome_message', $data);
        $this->load->view('common/footer');
    }

    public function content_top() {
        if ($this->uri->segment(1)) {
            $route = $this->uri->segment(1) .'/'. $this->uri->segment(2);
        } else {
            $route = 'common/home';
        }

        $layout_id = $this->model_layout->get_layout($route);

        $data['modules'] = array();

        $modules = $this->model_layout->get_layout_modules($layout_id, 'content_top');

        foreach ($modules as $module) {
            $part = explode('.', $module['code']);

            if (isset($part[1])) {
                $setting_info = $this->model_module->get_module($part[1]);

                if ($setting_info) {
                    $data['modules'][] = $this->$part[0]($setting_info);

                }
            }
        }


        return $this->load->view('common/content_top', $data);
    }

    public function slideshow($setting_info) {
        static $module = 0;

        $data['banners'] = array();

        $results = $this->model_banner->get_banner($setting_info['banner_id']);

        foreach ($results as $result) {
            $data['banners'][] = array(
                'banner_image' => $this->model_image->resize($result['banner_image'], $setting_info['width'], $setting_info['height'])
            );
        }

        $data['module'] = $module++;

        $data['resize_errors'] = $this->image_lib->display_errors();

        return $this->load->view('module/slideshow', $data);
    }
}
Run Code Online (Sandbox Code Playgroud)

Nas*_*hir 5

在 CI 中,当您加载视图并作为字符串打印时,需要将第三个参数作为“TRUE”传递。

<?php echo $this->load->view('headers/menu', '', TRUE);?>
Run Code Online (Sandbox Code Playgroud)