2013-07-23 1 views
0

에 걸쳐 나는 PHP로 프로그래밍이고 나는 웹 페이지를 통해 일정이 요소가 필요합니다
헤더, 사이드 바 & 바닥 글 (모든 PHP 파일)메이크업 헤더, 사이드 바 및 바닥 글 상수는 웹 사이트

모든 파일은 각각의 정의를 html을 생성하는 create_header()와 같은 함수들과 CSS 레이아웃이 있습니다. div id = "header", id = "sidebar"..)

실제 내용 페이지로 모두 그들은이 파일을 포함하고, 전화를 걸고, div를 통해 모든 레이아웃을 생성하고, 모든 컨텐츠가 div 클래스 = "content"내에 있습니다.

이 방법을 각 페이지에 사용하거나 어떤 방법을 사용해야합니까?

+0

login.php 나는 일반적인 관행은 다음 각 페이지 –

+0

1 개 파일을 포함 할 필요가있다 "namespace.php"라는 파일을 생성하여 일반적으로 사용되는 모든 것을 포함 스틱 생각 덕분에 더 편리 해졌고 덕분에 –

답변

0

이것은 내 응용 프로그램에서 사용하는 것입니다. 이 도움이된다면보기 :

site_config.php : 이것은 내 템플릿 모습입니다

<?php 

define('DIR_BASE', dirname(dirname(__FILE__))); 
define('DIR_CLASSES', DIR_BASE . '/classes/'); 

// this is specific to the site 
define('DIR_SITE', DIR_BASE . '/yoursite/'); 
define('SITE_NAME', 'yoursite'); 

// these would be specific to this site only 
define('DIR_SITE_VIEWS', DIR_SITE . 'views/'); 
define('DIR_SITE_COMPONENTS', DIR_SITE . 'components/'); 

define('BASE_URL', 'http://'.$_SERVER['SERVER_NAME']); 
define('SITE_URL', BASE_URL . '/yoursite'); 

// static content for the site 
define('DIR_STATIC', SITE_URL . '/static'); 
define('DIR_JS', DIR_STATIC . '/js'); 
define('DIR_CSS', DIR_STATIC . '/css'); 
define('DIR_SITE_IMG', SITE_URL . '/images'); 
?> 

같은 :

<?php 
// site_template.php 
// template for adding a new page directly under main directory of this site 
require_once('site_config.php'); 

$pgtitle = "Title of the Page"; 
include_once(DIR_SITE_VIEWS . 'site_header_begin.php'); 

// custom css/javascript goes here 
include_once(DIR_SITE_VIEWS . 'site_header_end.php'); 
?> 
<?php 
// main content of the page goes here 
?> 
<?php 
include_once(DIR_SITE_VIEWS . 'site_footer.php'); 
?> 

site_header_begin.php :

<!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"> 
    <head> 
    <title> 
    <?php if (isset($pgtitle) && ($pgtitle != '')){echo $pgtitle." :: ";}?></title> 
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
    <meta name="AUTHOR" content="" /> 
    <meta name="KEYWORDS" content="" /> 
    <meta name="DESCRIPTION" content="" /> 

    <!-- common css goes here --> 
    <script type="text/javascript" language="javascript" charset="utf-8" src="http://code.jquery.com/jquery-1.8.0.min.js"></script> 
    <script type="text/javascript" src="http://code.jquery.com/ui/1.8.17/jquery-ui.min.js"></script> 

site_header_end.php :

</head><!-- end the header here --> 
<body ><!-- start the body here --> 

site_footer.php :

 <div id="footer"><a name="pageFooter"></a> 
     </div> 
    </body> 
</html> 

이 머리글/바닥 글 "상수"를 동적으로 만들 것이며, 모든 것이 site_config.php 파일에 정의 된 상수로 정의됩니다. 적절한보기, 정적, 클래스 및 구성 요소 디렉토리를 추가하기 만하면됩니다. 이것이 도움이되는지 확인하십시오.

+0

THanks for answer하지만 ('DIR_STATIC', SITE_URL. '/ static'); 왜/정적인지, DIR_SITE는 wwww.mysite.com 일 수 있습니까? –

+0

필요가 없다면 거기에 둘 필요가 없습니다. 모든 js/css/img 파일을 정적 디렉토리에 저장하므로 특정 사이트에만 적용됩니다. – Maximus2012

+0

또한 DIR_SITE를 사용하면 절대 경로가 필요없이 파일을 포함/요구할 수 있습니다. 이 코드는 서버에 독립적입니다. site_config.php 파일을 변경하기 만하면됩니다. 필요에 따라 약간 사용자 정의해야 할 수도 있습니다. – Maximus2012

0

이것은 PHP로 프로그래밍 할 때 사용하는 시스템이며 잘 작동합니다. 모든 페이지에 포함물을 추가하는 것을 기억한다면 일관성을 유지하는 좋은 방법입니다. 또한 웹 사이트 레이아웃을 쉽게 업데이트 할 수 있습니다. PHP에는 템플릿이나 마스터 페이지가 없기 때문에 더욱 강력합니다. 그러나, 나는 <header>, <footer><sidebar>을 포함하여 HTML의 새로운 의미 론적 태그를 적절하게 추천 할 것입니다. id를 적절하게 <div>으로 지정하는 것이 좋습니다.

+0

덕분에 좋았지 만 잠재 고객 중 상당수는 여전히 IE 8을 사용하여 해당 특수 태그를 지원하지 않았다. –

0

include 함수는 웹 사이트 서식 파일을 일정하게 유지하는 좋은 방법입니다. 머리글과 왼쪽 창.

<?php 
//session maintenance code: 
?> 

<!DOCTYPE HTML> 
<html> 
<head> 
    <title>Admin interface</title> 
    <link rel="stylesheet" type="text/css" href="../css/pageBody.css" /> 
    <link rel="stylesheet" type="text/css" href="../css/dropdown.css"/> 

</head> 
<body> 
    <!--top divisor--> 
    <div id="topp"> 
     <center> 
      top pane content should be coded here 
     </center> 
    </div> 
    <!--end of the top divisor--> 

    < div id="bottom"> 
     <!--start of the left pane--> 
     <div id="leftd" > 
      <P> 
       left pane content should be coded here: 
      </P> 
     </div> 

in1.php (this file contains top part of the constant interface)

그런 다음 발 (바닥) 부분은

<!--start of the footer--> 
    <div id="foot" style=""> 
     <center class="footfix"> 
      &copy;KS <a href="http://ugvle.ucsc.cmb.ac.lk">visit us</a> 
     </center> 
    </div> 
    <!--end of the footer--> 

    <div></div> 
</body> 

</html> 

in2.php (this file contains the constant end part of the web site) 마지막으로 우리는 웹 사이트의 동적 인 부분을 정의 할 수 있습니다. 로그인 창을 보여 줬습니다.

<?php 
include 'in1.php'; //previously made top part 
?> 
     <!--start of the dynamic main pane--> 
     <div id="rightd" > 
      <form name="login" action="user.php" method="post"> 
       <table> 
        <tr><td>Email: </td><td colspan="2" ><input type="text" name="email" size="30" required/></td></tr> 
        <tr><td>password: </td><td colspan="2"><input type="text" name="pass" size="30" required/></td></tr> 
        <tr><td></td><td><input type="submit" value="OK" name="log"/><input type="reset" value="clear" /></td></tr> 
       </table> 
      </form> 

      <?php 
       //a php code here: 
      ?> 

     </div> 
     <!--end of the dynamic main pane--> 
<?php 
include 'in2.php'; //previously made footer part 
?> 
관련 문제