doushi4633 2013-05-02 19:15
浏览 12
已采纳

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

I am having problems displaying views with a template. My template looks like this:

<?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');
?>

By wrong position, I mean that my form is being displayed in the top lefthand corner outside of the HTML structure. Here is a copy from inspect element window. Notice where the div is located; the head tags are empty; and, the head information is in body.

<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>

Without loading that view, the HTML structure is fine. Also there is no problems with loading is_loggedin and not_logged into the views.

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">

And the footer contains:

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

From the controller I am passing the data like this:

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

Any ideas why everything is so messed up?

  • 写回答

1条回答 默认 最新

  • dongxi3911 2013-05-02 21:54
    关注

    Two ways of doing this:

    Codeigniter views

    Load it in advance (like you're doing) and pass to the other view

    There is a third optional parameter lets you change the behavior of the function so that it returns data as a string rather than sending it to your browser. This can be useful if you want to process the data in some way. If you set the parameter to true (boolean) it will return data. The default behavior is false, which sends it to your browser. Remember to assign it to a variable if you want the data returned:

    // 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;
    }
    

    Load a view "from within" a view:

    <?php
    // Controller
    $this->load->view('template');
    
    <?php
    // Views :  /application/views/template.php
    $this->view('vchangeinfo');
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!