2011-10-24 3 views
0

나는 포함을 사용하고자하는 함수가 있지만 클래스에 public 인 모든 vars가 페이지 레이아웃 포함 파일에 완전히 전달되어야합니다.클래스에서 Var를 포함하여 포함

vars는 함수 내에서 전달되지만 include로 전달 될 때는 전달되지 않습니다. 이 일을하기위한 쉬운 제안?

private function printGraph() { 
    /* 
    if($_SERVER['HTTP_HOST']=='localhost') { 
     echo "<pre>\n"; 
     echo "Actual: ".$this->actual."\n"; 
     echo "Actual Bar: ".$this->actualbar."\n"; 
     echo "Attainable Bar: ".$this->attainablebar."\n"; 
     echo "Attainable: ".$this->attainable."\n"; 
     echo "ADSL2Calc: ".$this->adsl2calc."\n"; 
     echo "</pre>"; 
    } 
    */ 

    //Adding the new look Tshooterlayout! 
    include 'tshooterlayout14.php'; 

    // Actual Speed info and bar 
    $actual=file_get_contents("inc/troubleshooter/tshoot3-actual.inc"); 
    $actual=sprintf($actual,$this->actual,$this->actualbar,$this->attainablebar); 

답변

1

그냥 사용 $이 :

test.php

<?php 
class Test { 
    public $foo = 'bar'; 

    public function testme(){ 
     include "include.php"; 
    } 

} 

$T = new Test(); 

$T->testme(); 

include.php

<?php 
echo "You got your " . $this->foo ." in my foo!\n"; 

결과

$ php test.php 
You got your bar in my foo! 
+0

너는 나의 영웅이야. 내가 지금 가지고있는 한 가지 문제는 Include 내에서 해당 함수 내에서 함수를 참조하고 있지만 이것이 내게 힘든 시간을 줄 수 있다는 것입니까? 노이즈 비율 : 치명적 오류 : 정의되지 않은 함수를 호출합니다 .NRV() /var/www/ADSLGeek/inc/troubleshooter/tshooterlayout14.php on line 236 –