2011-02-09 12 views
0

2つのファイルが必要です。 main.phpとのセカンダリファイル、私のコードで1呼び出してみましょう: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私はクラスに変数を渡す必要があります。私は削除することを意味:second.phpから

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

と私はmain.phpからこのデータを渡すことになる私はsecond.phpに変更する必要があり、どのようmain.phpになり何

そうするためには?

もし私が自分自身を説明していないなら、私にはまだ学生であり、おそらくまだボキャブラリーを台無しにしていると言ってください。ご使用のクラスは、あなたが本当にこれらのクラスを定義するファイルの中にあるものクラッセ上で操作を行うべきでない場合

どうもありがとう

答えて

0

。あなたはファイル内tagsクラスを定義する必要がありますあなたの状況与え例えば

は、そのファイルで行うので、あなたのmain.phpファイル、アプリケーションのランナーを行い、その後tags.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

関連する問題