php inheritance question?

J'sylve

New member
Here's my HW tasks:

Task #1 is to create the new CHILD class by extending the class Company. Create an object from your CHILD class so we can call the methods.

Task #2 Add the following properties (variables) to your PARENT class Company:
$company_url which will hold the web address of your web page. In this case it will be http://www.college1.com/users/[email protected]
$company_email which will be set to your email address [email protected]

Task #3 Add a variable to the CHILD class $navbar_array for creating a navigation bar on your web page.

Task #4 Copy and paste the method create_navbar_array() below into the CHILD class, it will initialize the array:

# create array for a Car/house/travel Nav Bar
function create_navbar_array ( ) {
$mainurl = $this->company_url; // get the main url address of this web page
$this->navbar_array = array( "Home Page"=>"$mainurl?whichpage=home", "Sales"=>"$mainurl?whichpage=sales",
"Support" => "$mainurl?whichpage=support", "Contacts" => "$mainurl?whichpage=contact" );
}

task #5 call and print of getHeader() and getFooter() make sure you call both create_navbar_array() and getLeftNavBar() and print the HTML table that getLeftNavBar() returns.




Here's the code I came up with:




class TravelAgent extends Company {

}
$travelobject = new TravelAgent();



function create_navbar_array ( ) {
$mainurl = $this->company_url;
$this->navbar_array = array( "Home Page"=>"$mainurl?whichpage=home", "Sales"=>"$mainurl?whichpage=sales",
"Support" => "$mainurl?whichpage=support", "Contacts" => "$mainurl?whichpage=contact" );
}



function getLeftNavBar($navbar_array) {

$data = "<TABLE BGCOLOR='#ffff00;' WIDTH='20%'><TR><TD ALIGN='left'>";
$data .=

foreach($navbar_array as $navigation){


$data.= "<tr><td>$navigation</tr>";}
data.= "</table></center></body></html>";
}


$data = $data . "</TD></TR></TABLE>";
return $data;
}


$travelobject->getHeader();

$travelobject->getLeftNavBar();

$travelobject->getFooter();



What's wrong in my code? Or am I doing the correct instructions?
 
Back
Top