사이트 안에 디렉터리 생성 후 다른 사이트 제작
본문
A 사이트가 있고, 관련된 B 사이트를 A 사이트 안에 제작하려고 합니다
A, B 과 연관된 사이트지만 디자인이 전혀 다른 사이트 입니다
head.php, tail.php, index.php 파일이 달라져야하는 상황입니다
코어파일을 최대한 건드리지 않으려고 하고,
brand 디렉터리 하나 생성해서 head.php, tail.php 파일도 생성하고,
extend 에 파일하나 생성해서
define('G5_BRAND_DIR', 'brand');
define('G5_BRAND_URL', G5_URL.'/'.G5_BRAND_DIR);
define('G5_BRAND_PATH', G5_PATH.'/'.G5_BRAND_DIR);
이렇게 추가하고,
/brand/b/index.php 파일에다가
define('_BRAND_', true);
if( defined('_BRAND_') ) {
require_once(G5_BRAND_PATH.'/index.php'); // head 엔 head, tail 엔 tail
return;
}
을 설정해놨습니다.
그런데 도메인/brand/b 를 접속하면 index 파일만 불러오고, head/tail 을 불러오질 않습니다;;
brand/b/index.php 파일을
<?php
include_once('../../_common.php');
define("_INDEX_", TRUE);
define('_BRAND_', true);
include_once(G5_PATH.'/head.php');
?>
브랜드메인
<?php
include_once(G5_PATH.'/tail.php');
이렇게 해놓았는데... 뭐가 잘못됐고 어떻게 불러와야 /brand/b 페이지를 기본 사이트와 다르게 구현할 수 있나요..?? !-->!-->!-->
답변 2
* extend 파일
// 브랜드 기본 경로 정의
define('G5_BRAND_DIR', 'brand');
define('G5_BRAND_URL', G5_URL.'/'.G5_BRAND_DIR);
define('G5_BRAND_PATH', G5_PATH.'/'.G5_BRAND_DIR);
// 현재 브랜드 감지
$request_uri = $_SERVER['REQUEST_URI'];
$pattern = '/\/'.G5_BRAND_DIR.'\/([^\/]+)/';
if (preg_match($pattern, $request_uri, $matches)) {
define('G5_CURRENT_BRAND', $matches[1]); // 브랜드명 (b, c 등)
define('G5_CURRENT_BRAND_PATH', G5_BRAND_PATH.'/'.G5_CURRENT_BRAND);
define('G5_CURRENT_BRAND_URL', G5_BRAND_URL.'/'.G5_CURRENT_BRAND);
define('_BRAND_', true);
}
* /index.php, head.php, tail.php
if ( defined('_BRAND_') ) {
include_once(G5_CURRENT_BRAND_PATH.'/index.php');
return;
}
아래의 내용을 한번 참고를 해보시겠어요..
1. extend 파일 수정하기
// extend/brand.extend.php
define('G5_BRAND_DIR', 'brand');
define('G5_BRAND_URL', G5_URL.'/'.G5_BRAND_DIR);
define('G5_BRAND_PATH', G5_PATH.'/'.G5_BRAND_DIR);
// URL에서 brand/b가 포함되어 있는지 검사
if (strpos($_SERVER['REQUEST_URI'], '/'.G5_BRAND_DIR.'/b/') !== false) {
define('_BRAND_', true);
}
2. 루트 head.php 수정
<?php
// 상단에 추가
if (defined('_BRAND_')) {
include_once(G5_BRAND_PATH.'/b/head.php');
return;
}
// 기존 코드
// ...
?>
3. 루트 tail.php 수정
<?php
// 상단에 추가
if (defined('_BRAND_')) {
include_once(G5_BRAND_PATH.'/b/tail.php');
return;
}
// 기존 코드
// ...
?>
4. /brand/b/index.php 수정
<?php
include_once('../../common.php');
define("_INDEX_", TRUE);
// define('_BRAND_', true); 이 부분은 extend 파일에서 이미 정의됨
// 브랜드 전용 메인 컨텐츠
?>
<!-- 메인 컨텐츠 -->
브랜드메인
<!-- /메인 컨텐츠 -->
<?php
// 따로 include_once를 호출하지 않아도 됨 - 자동으로 head.php와 tail.php가 적용됨
?>
5. /brand/b/head.php 생성
<?php
if (!defined('_GNUBOARD_')) exit; // 개별 페이지 접근 불가
// 브랜드 전용 head 내용
?>
<!doctype html>
<html lang="ko">
<head>
<meta charset="utf-8">
<title>브랜드 B 사이트</title>
<!-- 브랜드 전용 스타일시트 및 JS -->
<link rel="stylesheet" href="<?php echo G5_BRAND_URL; ?>/b/css/style.css">
</head>
<body>
<!-- 브랜드 전용 상단 메뉴 -->
<header>
<h1>브랜드 B 사이트</h1>
<nav>
<!-- 브랜드 전용 메뉴 -->
</nav>
</header>
<div id="main">
6. /brand/b/tail.php 생성
<?php
if (!defined('_GNUBOARD_')) exit; // 개별 페이지 접근 불가
// 브랜드 전용 tail 내용
?>
</div><!-- /main -->
<footer>
<!-- 브랜드 전용 푸터 -->
<p>© <?php echo date('Y'); ?> 브랜드 B 사이트</p>
</footer>
</body>
</html>
1. 사용자가 /brand/b/ 경로로 접속하면, extend/brand.extend.php 파일에서 BRAND 상수가 정의됩니다.
2. 그 후 common.php가 로드되고, 루트의 head.php와 tail.php가 호출될 때 BRAND 상수를 확인하여 브랜드 전용 파일로 대체합니다.