2011-02-09 74 views
0

我需要有兩個文件。 讓我們把文件控制的第二個:main.php和我們稱之爲輔助文件,一個與我的代碼:second.php從外部文件傳遞參數到一個類

在second.php我:

<?php 

class tags{ 

    var $theuser; 
    var $thebarname; 
    var $theplace; 
    var $thetime; 
    var $themail; 

    function __construct($theuser,$thebarname,$theplace, $thetime, $themail){ 
     $this->theuser=$theuser; 
     $this->thebarname=$thebarname; 
     $this->theplace=$theplace; 
     $this->thetime=$thetime; 
     $this->themail=$themail; 

    } 

    function give_tags_theuser(){ 
     return $this->theuser; 
    } 
    function give_tags_thebarname(){ 
     return $this->thebarname; 
    } 

    function give_tags_theplace(){ 
     return $this->theplace; 
    } 

    function give_tags_thetime(){ 
     return $this->thetime; 
    } 
    function give_tags_themail(){ 
     return $this->themail; 
    } 
} 


$tags = new tags("John", "Starbucks", "NY", "4:30", "[email protected]"); 

$user= $tags->give_tags_theuser(); 
$barname = $tags->give_tags_thebarname(); 
$place = $tags->give_tags_theplace(); 
$time = $tags->give_tags_thetime(); 
$email = $tags->give_tags_themail(); 

// with the data before I will send an email using phpmailer, but that's another story 
?> 

在主。 PHP我需要將變量傳遞給類。這意味着我將刪除:

$tags = new tags("John", "Starbucks", "NY", "4:30", "[email protected]"); 

從second.php,我會從main.php可以通過這個數據

什麼我有second.php改變,以及如何將main.php是爲了這樣做?

如果我沒有解釋我自己,請告訴我,我仍然是一名學生,我可能還在搞亂詞彙。

非常感謝

回答

0

如果您使用的類,那麼你真不該在定義這些類裏面的文件的CLASSE做操作。

例如給你的情況,你應該定義一個名爲tags.php文件中的tags類,然後讓你的main.php文件應用程序的亞軍,所以在該文件中做:

require_once 'tags.php' 
$tags = new tags("John", "Starbucks", "NY", "4:30", "[email protected]"); 

$user= $tags->give_tags_theuser(); 
$barname = $tags->give_tags_thebarname(); 
$place = $tags->give_tags_theplace(); 
$time = $tags->give_tags_thetime(); 
$email = $tags->give_tags_themail(); 

這比寫代碼更好它在多個文件中運行你的應用程序。

+0

非常感謝! – user523129 2011-02-09 17:32:36

相關問題