2012-05-14 3 views
0

내 사이트 전체에 header.php 파일을 갖고 싶습니다. 나는조차 할 수없는,함수에서 포함 된 파일 내 변수 사용

header.php

<head> 
    <meta charset="utf-8"> 
    <link rel="stylesheet" href="<?php if(isset($depth)){echo $depth;};?>css/style.css"> 

functions.php

function include_layout_template($template="", $depth="") 
{ 
    global $depth; 
    include(SITE_ROOT.DS.'public'.DS.'layouts'.DS.$template); 
} 

index.php를

<?php include_layout_template('header.php', "../"); ?> 

그러나 $ 깊이 사라짐 : 저는 현재 다음이 echo $ depth; 그냥 비어 있습니다. header.php에서 사용할 깊이 변수를 어떻게 얻을 수 있습니까? 이 첫 번째 매개 변수로 전달하지만 글로벌 매개 변수를 사용하도록 정의되어 있기 때문에

+2

$ depth는 전역 변수이며'include_layout_template '함수의 매개 변수입니다. 그 일이 엉망이 될거야 ... – Yaniro

답변

2

당신은, 함수 호출

function include_layout_template($template="", $my_depth="") 
{ 
    global $depth; 
    //if need $depth = $mydepth 
0

귀하의 $depth 변수가 사라지고 깊이 변수의 이름을 변경해야합니다.

내가 예와 함께 설명합니다 :

$global = "../../"; //the variable outside 
function include_layout_template($template="", $depth="") 
{ 
    global $depth; //This will NEVER be the parameter passed to the function 
    include(SITE_ROOT.DS.'public'.DS.'layouts'.DS.$template); 
} 
include_layout_template("header.php", "../"); 

은 단순히 깊이 자체보다 다른 기능 매개 변수를 수정, 해결하기 위해.

function include_layout_template($template="", $cDepth="") { }