Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/288.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 将数据从我的控制器codeigniter传递到我的视图中_Php_Codeigniter_Templates_Variables - Fatal编程技术网

Php 将数据从我的控制器codeigniter传递到我的视图中

Php 将数据从我的控制器codeigniter传递到我的视图中,php,codeigniter,templates,variables,Php,Codeigniter,Templates,Variables,我已经为我的项目构建了一个布局模板(请参见布局功能)。模板系统将页眉、页脚和左视图添加到页面中,并将当前视图呈现为“middle” 问题是我不能正确地包含$data变量。这是为了让我的数据打印出来,我需要像下面选项1一样包括它 选项1 $this->load->view('profile_view', $data); 布局功能 public function layout () { $this->templa

我已经为我的项目构建了一个布局模板(请参见布局功能)。模板系统将页眉、页脚和左视图添加到页面中,并将当前视图呈现为
“middle”

问题是我不能正确地包含
$data
变量。这是为了让我的数据打印出来,我需要像下面选项1一样包括它

选项1

  $this->load->view('profile_view', $data);
布局功能

                public function layout () {
                $this->template['header'] = $this->load->view('layout/header', $this->Front_End_data, true);
                $this->template['left'] = $this->load->view('layout/left', $this->Front_End_data, true);
                $this->template['middle'] = $this->load->view($this->middle, $this->Front_End_data, true);
                $this->template['footer'] = $this->load->view('layout/footer', $this->Front_End_data, true);
                $this->load->view('layout/index', $this->template);
这可以渲染模板,但我需要包含
$data

function index()
{
    $data = array();
    $this->load->model('user_profile/profiles_model');
    $query = $this->profiles_model->get_bank();

    if (!empty($query)) {
        $data['records'] = $query;
    }

    $this->middle = 'profile_view';
    $this->layout();
}    
什么是最好的解决方案

更新

我尝试了一些似乎部分有效的方法,但复制了两次视图,一次在正确的位置,一次错误,有什么想法吗

function index()
    {
        $data = array();
        $this->load->model('user_profile/profiles_model');
        $query = $this->profiles_model->get_bank();

        if (!empty($query)) {
            $data['records'] = $query;
        }
//        $this->middle = 'profile_view';
        $this->load->view($this->middle = 'profile_view',$data);
        $this->layout();
//        $this->layout($data);
    }
更新

这也行,但不是最好的方法

function index()
    {
        $data = array();
        $this->load->model('user_profile/profiles_model');
        $query = $this->profiles_model->get_bank();

        if (!empty($query)) {
            $data['records'] = $query;
        }

//        $this->load->view($this->middle = 'profile_view',$data);
        $this->template['middle'] = $this->load->view ($this->middle = 'profile_view',$data, true);
        $this->layout();

//        $this->middle = 'profile_view';
//        $this->layout($data);
    }

使用Phil Sturgeon创建的。这是可怕的,非常容易设置和使用。我用codeigniter构建的任何项目这是我添加的第一件事。既然已经有可用的平面,为什么还要重新创建控制盘?

为什么不简单地将
$data
传递给布局方法

    $this->layout($data);

它并不优雅,但我是这样修好的

$this->template['middle'] = $this->load->view ($this->middle = 'pages/update_view',$data, true);
        $this->layout();

模板是什么?风景?图书馆?你的问题不是描述性的。@Kisaragi好的,谢谢,我会解决我的问题这里有另一种方法@cartalot谢谢,我会看看的。嗯,我考虑过这个问题,但是数据没有呈现出来