2010-03-30 3 views
0

좋아, 내 친구가 나를 위해 만든 템플릿 스크립트가 있습니다. 모든 파일 이름을 포함하겠습니다.PHP 템플릿 사이트/file_get_content 링크

확인 그래서 작동하지 않는 것은 file_get_contents는 내용이 배치되어야 모르겠어요 내용

(1 grabing되지이다.

(2 나는 그것이 있도록 디렉토리에 위치합니다 템플릿을 변경하면 콘텐츠가있는 영역이 동일하게됩니다.

(3 링크를로드하려면 file_get_contents를 가져오고 싶습니까? = about? = 콘텐츠 등을 body.tpl에 지정한 div에서 지정했습니다. # CONTENTS #

(4T 그는 Dir Tree는 다음과 같습니다.

htdocs> 
    classes> file.class.php 
    contents> where i want #CONTENTS# (file_get_contents) to grab data from 
    images> content (changing images) 
    templates> where the templates are hosted 
      clean>main template (Files are header.tpl, body.tpl, footer.tpl, styles.css, menu_style.css, and the images folder for images relating to the template itself.) 
      other templates>(to come) 

어떤 도움을 주셔서 감사합니다. 이제 문제는 스크립트가 모든 것을 올바른 영역에 넣고 표시하는 것입니다./* file.class.php */

<?php 

$file = new file(); 

class file{ 
    var $path = "templates/clean"; 
    var $ext = "tpl"; 

    function loadfile($filename){ 
    return file_get_contents($this->path . "/" . $filename . "." . $this->ext); 
} 

function setcontent($content,$newcontent,$vartoreplace='#CONTENT#'){ 
    $val = str_replace($vartoreplace,$newcontent,$content); 
    return $val; 
} 

function p($content) { 
    $v = $content; 
    $v = str_replace('#CONTENT#','',$v); 
    print $v; 
} 
} 
if(!isset($_GET['page'])){ 
    // if not, lets load our index page(you can change home.php to whatever you want: 
    ob_start(); 
    include("contents/".'main.php'); 
    $content = ob_get_contents(); 
    ob_end_clean(); 
    // else $_GET['page'] was set so lets do stuff: 
    } else { 
    // lets first check if the file exists: 
    if(file_exists($_GET['page'].'.php')){ 
    // and lets include that then: 
    ob_start(); 
    include("contents/". $_GET['page'] . '.php'); 
    $content = ob_get_contents(); 
    ob_end_clean(); 


    // sorry mate, could not find it: 
    } else { 
     echo 'Sorry, could not find <strong>' . $_GET['page'] .'.php</strong>'; 
    } 
} 
?> 

몇 가지 중 하나가 아래로 트림 할 수 있다면

은 그래서 그냥 템플릿 필요한 코드 및 파일 내용을 얻을 수 있습니다.

/* *의 index.php/

<?php 
    include('classes/file.class.php'); 

    // load the templates 
    $header = $file->loadfile('header'); 
    $body = $file->loadfile('body'); 
    $footer = $file->loadfile('footer'); 

    // fill body.tpl #CONTENT# slot with $content 
    $body = $file->setcontent($body, $content); 

    // cleanup and output the full page 
    $file->p($header . $body . $footer); 

?> 

/* * header.tpl/

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-Transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/> 
<meta name="robots" content="index,follow"/> 
<meta name="distribution" content="global"/> 
<meta name="description" content=""/> 
<meta name="keywords" content=""/> 
<link href="templates/clean/style.css" rel="stylesheet" type="text/css" media="screen" /> 
<link rel="stylesheet" href="templates/clean/menu_style.css" type="text/css" /> 
<script type="text/javascript" src="http://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js"></script> 
</head> 
<body> 
<div id="header"> 
    <div id="logo"><a href="index.php" style="height:30px;width:150px;"><img src="images/logo.png" border="0" alt=""/></a></div> 
    <div id="menuo"> 
    <div class="menu"> 
    <ul id="menu"> 
     <li><a href="?page=home">Home</a></li> 
     <li><a href="?page=about">About Us</a></li> 
     <li><a href="?page=services">Services</a> 
     <ul> 
     <li><a href="?page=instore">InStore Repairs</a></li> 
     <li><a href="?page=inhome">InHome Repairs</a></li> 
     <li><a href="?page=website">Website Design</a></li> 
     <li><a href="?page=soon">Comming Soon.</a></li> 
     </ul> 
     </li> 
     <li><a href="?page=products">Products</a> 
        <ul> 
        <li><a href="?page=pchard">Computer Hardware</a></li> 
        <li><a href="?page=monitor">Monitor's</a></li> 
        <li><a href="?page=laptop">Laptop + Netbooks</a></li> 
        <li><a href="?page=soon">Comming Soon.</a></li> 
        </ul> 
      </li> 
     <li><a href="?page=contact">Contact</a></li> 
    </ul> 
    </div> 
    </div> 
</div> 
<div id="headerf"> 
</div> 

/* * body.tpl/

<div id="bodys"> 
    <div id="bodt"></div> 
     <div id="bodm"> 
      <div id="contents"> 
       #CONTENT# 
       </div> 
    <div id="bodb"></div> 
     </div> 
</div> 

/* foo ter.tpl */

<div id="footer"> 
<div style="position:absolute; top:4px; left:4px;"><img src="images/ff.png" alt="ok"></div> <div style="position:absolute; top:4px; right:5px; color:#FFFFFF;">&copy;2010 <a href="mailto:">Company Name</a></div> 
</div> 
</body> 
</html> 
+0

을하는 데 도움이

if(file_exists('contents/'.$_GET['page'].'.php')){ 

희망을 읽어야 문제가 라인

if(file_exists($_GET['page'].'.php')){ 

에있을 수 있습니다 생각 html이 아닙니다 validator.w3.org가 비행 색상으로 전달되었습니다.이 사이트를보아야 할 필요가있는 사용자라면 누구나 볼 수 있습니다. designed.sytes.net – Zeenjayli

답변

2

내가 이해하는 바에 따르면 귀하의 콘텐츠는 약 .php (예 :)입니다.

about.php/내용 인라인 about.php 스크립트 을로드하고 실행할 명령

include('about.php') 

:

이 파일은 "내용"디렉토리에 있습니다. 따라서 호출이 포함 된 정확한 내용이 인쇄됩니다. 당신이 같이 있어야 참조 : 올바른 값을 가지고 $ 내용,

ob_start(); 
include("contents/". $_GET['page'] . '.php'); 
$content = ob_get_contents(); 
ob_end_clean(); 

와 라인

include($_GET['page'].'.php'); 

을 변경하려는 경우

(content of about.php) | header | body | footer 

이 객체 버퍼링 기술을 사용합니다 PHP가 파일의 내용을 렌더링해서는 안되지만 대신 $ content 변수에 넣어야한다는 것을 PHP가 이해하도록합니다.

나는 희망한다.

+0

나는 당신이 말한 것을 시도해 보았지만 그것은 변하지 않았습니다. 나는 모두에서 그것을 업데이 트했습니다. – Zeenjayli

+0

"about.php"가 "contents/about.php"에 있다는 사실을 고려하여 수정했습니다. 작동하는지 말해봐. "폭발"버전 ob_start/ob_end_clean을 유지하지 마십시오. 당신은 가지고 있어야합니다 ob_start(); INCLUDE (.....) $ content = ob_get_contents(); ob_end_clean(); 각 주변에는 이 있습니다. 이것이 명확하지 않은지 명확히 할 것입니다. 그래도 해결되지 않으면 에 대해 자세히 설명해주세요. 1/브라우저에서 사용하는 URL은 무엇입니까? 2/무엇을보고 계십니까? 제롬 –

+0

천재! 덕분에 많은 내용을 훌륭하게 작동하는 곳이 지금 있어야합니다 (내용/main.php를 찾고 있었기 때문에 발견되었습니다. 그래서 폴더에 넣을 때까지 용어를 찾지 못해서 새로운 문제가 나타납니다. 콘텐츠가 표시되지 않는 곳으로 올리겠습니다. 내가 한 일을 보여주기 위해 코드를 업데이트했습니다. – Zeenjayli

1

친구가 만든 기본 스크립트는 사이트 템플릿 작성에 도움이되는 도우미 기능으로 채워집니다. , 템플릿

의 위치 현재 템플릿 메커니즘

1을 사용

  1. 템플릿의 위치
  2. :

    현재, 난 당신이 문제가 있다고 생각 친구의 상태는

    var $path = "templates/clean"; 
    
    당신이 템플릿을 폴더와 당신의 index.php을 넣어 한 디렉토리에 템플릿/청소 폴더를 만들고 템플릿을 (header.tpl, body.tpl, footer.tpl를 넣어해야한다는 것을 의미

    ) 내부.

    2.템플릿 메커니즘을 사용하여

    사전로드 body.tpl에서 # 콘텐츠 #의 선두로부터 찾을

    <?php 
        include('classes/file.class.php'); 
    
        // load the templates 
        $header = $file->loadfile('header'); 
        $body = $file->loadfile('body'); 
        $footer = $file->loadfile('footer'); 
    
        // fill body.tpl #CONTENT# slot with "Hello World!" 
        $body = $file->setcontent($body, "Hello World!"); 
    
        // cleanup and output the full page 
        $file->p($header . $body . $footer); 
    
    ?> 
    

    의 setContent를 사용하여 시도하고 (이 경우 특정 내용으로 대체, "안녕하세요")

    나는 이것이 당신을 좋은 길로 인도하기를 희망한다! 작동하는지 말해봐. 제롬

+0

ok 그래서 "$ body = $ file-> setcontent ($ bod y, $ content); " 네가 말했듯이 "Hello World!" ($ _GET [ 'page']) { $ content = $ _GET [ 'page']. '. php'태그를 읽으면 해당 태그를 읽습니다. ; } else { $ content = 'main.php'; } "그래서 나는 대략을 클릭하고 스크립트는 Zeenjayli

0

나는 그것은 그래서 그것이 적어도 지금은 잘 CSS/HTML의 문제가 아니라 알고이