2013-05-02 4 views
0

템플릿으로보기를 표시하는 데 문제가 있습니다. 내 템플릿은 다음과 같습니다 : 잘못된 위치에 의해CI 템플릿 - 요소가 잘못된 위치에 표시됩니다.

<?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 요소 창에서 복사 한 것입니다. 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를로드해도 아무런 문제가 없습니다.

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

을 그리고 바닥 글에는 다음이 포함됩니다 :

내 헤더가 포함

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

어떤 아이디어가 모든 이유 :이 같은 데이터를 전달하고 컨트롤러에서

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

그래서 엉망이 됐어?

답변

0

두이 일을하는 방법 : 사전에

Codeigniter views

로드 그것은 (당신이하고있는 것처럼)와

제 3 선택적 매개 변수를 할 수 있습니다 다른보기에 전달 함수를 브라우저로 보내지 않고 문자열로 반환하도록 함수의 동작을 변경하십시오. 이는 데이터를 어떤 방식으로 처리하려는 경우에 유용 할 수 있습니다. 매개 변수를 true (부울 값)로 설정하면 데이터를 반환합니다. 기본 동작은 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'); 
+0

예, 감사합니다. $ this-> load-> view ($ content) 뷰를로드하면 echo $ content가 작동합니다. 이 코드 줄 아래의 모든보기가 작동하지 않지만 위의 모든보기가 잘로드 중입니다 ..... 궁금한 이유는 ... – Merkley

+0

아마도 $ this-> load-> view ($ content) ; 컨트롤러에서 한 번만 실행하고 다른 시간은보기에서 수행합니다. (확실하지는 않지만 어쩌면 설명 할 수 있음) – Simon

관련 문제