2011-10-24 11 views
0

私はインクルードを使用したいと思う機能を持っていますが、クラス内のすべてのvarsをページレイアウトインクルードファイルにきれいに渡す必要があります。クラスからVarをインクルードするには

varsは関数内に渡されますが、インクルードに渡されるときは渡されません。これを行うための簡単な提案?

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

だけ使用します$ this:

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

魅力的な作品!あなたは私のヒーローです。 今私が持っている1つの問題は、Include内のその関数内の関数を参照していますが、それは私に苦労しています。 ノイズ比:致命的なエラー:/var/www/ADSLGeek/inc/troubleshooter/tshooterlayout14.php on line 236の未定義関数calculateSNR()を呼び出します。 –

関連する問題