Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Well done!
You have completed Extending Object-Oriented PHP!
You have completed Extending Object-Oriented PHP!
Preview
In this video we will extend the child class from ListingPremium. This new grandchild will inherit all the attributes and abilities of ListingPremium AND ListingBasic.
$object = new ListingFeatured();
//parent
echo is_a($object, 'ListingPremium'); //returns true
//grandparent
echo is_a($object, 'ListingBasic'); //returns true
//sibling of parent
echo is_a($object, 'ListingInactive'); //returns false
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
For our ListingFeatured class,
we're going to add a code of conduct.
0:00
The code of conduct is going to
work much like the description.
0:04
So let's copy the code from
the ListingPremium and modify that.
0:07
We don't need to change the allowed tags.
0:21
We'll let the ListingPremium handle that,
so let's remove that line.
0:23
Now we can change description to
code of conduct, or coc for short.
0:31
We update the set values, getCoc,
0:50
And setCoc.
1:05
Let's update our collection
to use this new listing.
1:12
Once again we'll modify our addListing
method to use this new class.
1:17
Now let's update the statuses.
1:32
We want our featured
listings to show up first.
1:36
So let's add it first to this list.
1:39
Next, let's update our form.
1:44
Once again we can copy the code from the
description and make a few minor changes.
1:48
Coc, coc, coc, Featured.
2:02
GetCoc.
2:13
We'll call this Code of Conduct.
2:18
And say Featured Only.
2:23
Finally, we need to update our listing.
2:25
We'll start by adding another
case to our switch statement.
2:31
If featured, Then we'll use panel-success,
2:36
And break, now,
let's show the code of conduct.
2:48
We'll make this a footer.
2:52
If (is_a($listing,
2:57
'ListingFeatured').
3:02
&& !empty
3:12
($listing->getCoc()))
3:16
div class="panel-footer"
3:31
id="coc
3:39
$listing->getId()
3:47
Let's preview this in the browser and
upgrade one of our listings.
4:06
It looks good, but instead of
having this displayed all the time,
4:26
let's add a toggle link.
4:29
We'll copy that, and
we'll put our link here.
4:38
Onclick="toggle(\'coc'.
4:56
$listing->getID()
5:06
Code of Conduct.
5:19
Let's set the style to
start as a display:none.
5:33
Let's clean up the text
from our homepage too.
5:45
And we can preview once more.
5:54
Great job, we have featured listings,
6:04
premium listings, basic and inactive.
6:08
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up