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 Designing Interfaces in PHP!
You have completed Designing Interfaces in PHP!
Preview
Extending an Abstract Class
This video doesn't have any notes.
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
To include a second type of content,
0:00
the first thing we need to
do is create a pages class.
0:02
Create a new file in source Classes.
0:05
We'll name this Pages.php.
0:08
Our class Pages extends the collection.
0:15
[SOUND] This means that we have two
methods that must be implemented.
0:22
The get title method,
from the collection interface and
0:28
the set entity method,
from the collection class.
0:32
Protected function setEntity.
0:36
This entity equals pages.
0:48
Public function getTitle.
0:56
And then,
since we are always using a single page,
1:04
we can set this method to always
return the current title.
1:08
return $this->current()->title.
1:14
Now we can rename
the index file to blog.php.
1:20
Then we can create a new
file named index.php.
1:29
First, let's add all the required files.
1:41
[SOUND] Require the config.
1:43
[SOUND] Require the view,
1:48
views header.php.
1:53
Require 'views/single.php' and
1:58
require 'views/footer.php';.
2:05
Since we're going to show
pages only as a single item,
2:13
we can use the single.php file.
2:17
Next, we need the content for our page.
2:20
Content equals new pages.
2:28
We'll pass the repo, and
then 1 to find the page.
2:31
Let's take a look at our site now.
2:37
We now see only the welcome page.
2:43
We don't have a way to pull other pages
right now, but, if we type blog.php,
2:46
we can see the blog posts
that we set up earlier.
2:55
Let's add the ability to
pull the rest of our pages.
2:59
We're going to use the slug
field from our page data.
3:02
So we'll set slug equal to home for
our home page.
3:07
Now we can change our initialization
to use the slug variable.
3:12
We'll pass slug, and we also need
to tell it to use the slug field.
3:17
Now we can change the slug variable
based on the page we wish to display.
3:23
Once again, we'll use if is set and
the get variable.
3:29
We'll check for slug.
3:36
And if that's set,
we'll set our slug equal
3:41
to filter_input(INPUT_GET, 'slug',
3:47
and then FILTER_SANITIZE_STRING).
3:53
Let's go back to our site and
see this in action.
4:02
Our home page is still working, and
4:09
if we type ?slug=about-us,
4:13
we can see the About Us page.
4:18
We are almost done.
4:24
To finish our site,
4:25
we need to add some navigation as well
as a featured image to our pages.
4:26
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