CI模板元素显示在错误的位置


CI template - element is displayed in wrong place

我有一个模板显示视图的问题。我的模板看起来像这样:

<?php
$this->load->view('includes/header');
if($this->session->userdata('is_loggedin')!=1) //check if logged in 
{
    $this->load->view('includes/not_loggedin');  //includes this when not logged in
} 
else //includes all this when is logged in
{
     if(isset($content)) //check if content variable isnt empty
     {
         $this->load->view($content); //THIS IS MY CONTENT WHIC IS DISPLAYED IN WRONG POS
     }
    $this->load->view('includes/is_loggedin'); //
}
$this->load->view('includes/footer');
?>

错误的位置,我的意思是我的表单被显示在左上角的HTML结构之外。这是一个来自inspect element窗口的拷贝。注意div的位置;头标签是空的;头部信息在身体里。

<html lang="en">
<head></head> //head tags are empty
<body>
<div id="settings">...</div>  //this is my loaded div 
<meta charset="utf-8">
<title>Sludinājumu lapa</title> //head info outside tags
<link href="/assets/css/style.css" type="text/css" rel="stylesheet">
<div id="wrapper">....</div>  //i need settings div inside wrapper div 
</body>
</html>

不加载该视图,HTML结构就可以了。此外,加载is_loggedin和not_logged到视图中也没有问题。

My header contains:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Sludinājumu lapa</title>
<link rel="stylesheet" type="text/css" href="/assets/css/style.css">
</head>
<body>
<div id="wrapper">

页脚包含:

<foter>
<p>developed by kriss</p>
</foter>
</div> //End of "wrapper" div
</body>
</html>

从控制器我传递这样的数据:

    $data['content'] = $this->load->view('vchangeinfo');
    $this->load->view('template', $data);

你知道为什么一切都这么乱吗?

有两种方法:

Codeigniter的观点

预先加载它(就像你正在做的那样)并传递给另一个视图

还有第三个可选参数,可以让您更改函数的行为,以便它以字符串形式返回数据,而不是将其发送到浏览器。如果您想以某种方式处理数据,这可能很有用。如果你将参数设置为true (boolean),它将返回数据。默认行为为false,它会将其发送到浏览器。如果您希望返回数据,请记住将它赋值给一个变量:

// the "TRUE" argument tells it to return the content, rather than display it immediately
$data['content'] = $this->load->view('vchangeinfo', NULL, TRUE);
$this->load->view ('template', $data);
// View
if(isset($content)) //check if content variable isnt empty
{
    $this->load->view($content);
    // OR don't know wich one works.
    // echo $content;
}

从视图内加载视图:

<?php
// Controller
$this->load->view('template');
<?php
// Views :  /application/views/template.php
$this->view('vchangeinfo');