2013-05-02 19:15
浏览 12

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

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


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


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

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">
<meta charset="utf-8">
<title>Sludinājumu lapa</title>
<link rel="stylesheet" type="text/css" href="/assets/css/style.css">
<div id="wrapper">

And the footer contains:

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

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
        // OR don't know wich one works.
        // echo $content;

    Load a view "from within" a view:

    // Controller
    // Views :  /application/views/template.php
    解决 无用
    打赏 举报

相关推荐 更多相似问题