我有一个简单的PHP表单,将查询提交到几个类中。应用程序的想法是传入乐队名称并检查场地以查看该乐队是否正在播放。如果那个乐队正在播放它,应用程序将回显乐队和乐队正在播放的日期。我已经设法让应用程序工作时,它的所有一个PHP文件,但我有麻烦吐出单个PHP文件到单独的类。
html表格:
<form action = "Ass1.php" method = "GET">
<b>Enter band name : </b>
<input type="text" name="bandName" />
<input name="submit" type="submit" value="Click" />
</form>
整个php文件有效:
<?php
class Concert {
public $Artist = '';
public $Date = '';
function SetConcert( $NewArtist = '', $NewDate = '' ) {
$this->Artist = $NewArtist;
$this->Date = $NewDate;
}
function GetArtist() {
return $this->Artist;
}
function GetDate() {
return $this->Date;
}
}
class Venue {
public $VenueName = '';
public $ConcertsInVenue = array();
function SetVenueName( $NewVenue = '' ) {
$this->VenueName = $NewVenue;
}
function GetVenueName() {
return $this->VenueName;
}
function AddConcert( $NewArtist = '', $NewDate = '' ) {
$NewConcert = new Concert;
$NewConcert->SetConcert( $NewArtist, $NewDate );
$this->ConcertsInVenue[] = $NewConcert;
}
function ListConcertsInVenue( $SearchQuery = '' ) {
//Assume Results Will Be Filtered
$ListAllConcerts = FALSE;
//If Search Query Is Blank, List All Concerts
if( $SearchQuery == '' ){
$ListAllConcerts = TRUE;
}
echo 'Concerts In '.$this->VenueName.':';
//Loop Through All Concerts In This Venue
foreach( $this->ConcertsInVenue as $tmpConcert ){
if( $SearchQuery == $tmpConcert->GetArtist() || $ListAllConcerts == TRUE ){
echo '<p>';
echo $tmpConcert->GetArtist().', ';
echo $tmpConcert->GetDate();
echo '</p>';
}
}
}
}
//Create New Venue Object
$tmpVenue = new Venue;
//Set Venue Name
$tmpVenue->SetVenueName( 'Wembley' );
//Add Concerts To Venue
$tmpVenue->AddConcert( 'Rollin\' Empire', '05-02-2018' );
$tmpVenue->AddConcert( 'Metallica', '06-02-2018' );
$tmpVenue->AddConcert( 'Led Zeppelin', '07-02-2018' );
$tmpVenue->AddConcert( 'Rollin\' Empire', '19-02-2018' );
//Search For Artist In Venue ( Leave Blank To List All )
$tmpVenue->ListConcertsInVenue($_GET['bandName']);
?>
我尝试创建3个类Venue.class.php Concert.class.php和app.class.php并且它无法正常工作
concert.class.php
<?php
include ("Venue.class.php");
class Concert {
public $Artist = '';
public $Date = '';
function SetConcert( $NewArtist = '', $NewDate = '' ) {
$this->Artist = $NewArtist;
$this->Date = $NewDate;
}
function GetArtist() {
return $this->Artist;
}
function GetDate() {
return $this->Date;
}
}
?>
Venue.class.php
<?php
include ("Concert.class.php");
class Venue {
public $VenueName = '';
public $ConcertsInVenue = array();
function SetVenueName( $NewVenue = '' ) {
$this->VenueName = $NewVenue;
}
function GetVenueName() {
return $this->VenueName;
}
function AddConcert( $NewArtist = '', $NewDate = '' ) {
$NewConcert = new Concert;
$NewConcert->SetConcert( $NewArtist, $NewDate );
$this->ConcertsInVenue[] = $NewConcert;
}
function ListConcertsInVenue( $SearchQuery = '' ) {
//Assume Results Will Be Filtered
$ListAllConcerts = FALSE;
//If Search Query Is Blank, List All Concerts
if( $SearchQuery == '' ){
$ListAllConcerts = TRUE;
}
echo 'Concerts In '.$this->VenueName.':';
//Loop Through All Concerts In This Venue
foreach( $this->ConcertsInVenue as $tmpConcert ){
if( $SearchQuery == $tmpConcert->GetArtist() || $ListAllConcerts == TRUE ){
echo '<p>';
echo $tmpConcert->GetArtist().', ';
echo $tmpConcert->GetDate();
echo '</p>';
}
}
}
}
?>
app.php
<?php
include ("Venue.class.php");
include ("Concert.class.php");
//Create New Venue Object
$tmpVenue = new Venue;
//Set Venue Name
$tmpVenue->SetVenueName( 'Wembley' );
//Add Concerts To Venue
$tmpVenue->AddConcert( 'Rollin\' Empire', '05-02-2018' );
$tmpVenue->AddConcert( 'Metallica', '06-02-2018' );
$tmpVenue->AddConcert( 'Led Zeppelin', '07-02-2018' );
$tmpVenue->AddConcert( 'Rollin\' Empire', '19-02-2018' );
//Search For Artist In Venue ( Leave Blank To List All )
$tmpVenue->ListConcertsInVenue($_GET['bandName']);
?>
我是否需要在app.php中创建一个新类来处理表单输入并将其传递给其他类?