Extending the Display7:40 with Alena Holligan
We're going to add some finishing touches to the display of our directory.
Declaring class properties or methods as static makes them accessible without needing an instantiation of the class. A property declared as static cannot be accessed with an instantiated class object. Because static methods are callable without an instance of the object created, the pseudo-variable $this is not available inside the method declared as static. Instead they use a keyword (e.g. self, parent and static).
Static methods cannot be overridden.
To learn more about the keyword differences, check out Late Static Binding.
For a refresher on "switch statements" check out the course PHP Arrays and Control Structures: Feature Switch This Week. Or check out the documentation for switch
We're going to add some finishing touches to the display of our directory. 0:00 In the form, we want to display the allowed tags. 0:03 Because the property is protected, 0:07 we'll need to create a getter that will show us the tags. 0:09 I also want this method to be accessible without creating a listing object, 0:13 so we'll need to make this method public and static. 0:18 Public static function, 0:25 displayAllowedTags. 0:30 And I want this to return the static 0:37 property self::$allowed_tags. 0:42 I also need to use the htmlspecialchars to convert the HTML 0:47 tags to be shown to the user. 0:52 We're ready to call our static method. 1:02 In our form listing, after the description label we'll add Allowed Tags. 1:06 Listing Premium, 1:15 displayAllowedTags. 1:19 Let's check this out in the browser. 1:25 Great, we can see which tags are allowed. 1:29 We also wanna update our listing. 1:32 So let's go back and open Views List item. 1:34 First, we need to add the description. 1:41 We're going to add this in the panel body. 1:45 We'll check if is a listing, 1:48 listing premium, 1:55 and not empty. 1:59 Listing get 2:07 description. 2:11 Echo, we'll add some new p tags for 2:17 a paragraph, listing, get description, 2:21 and close the paragraph. 2:27 Let's also update the style of the listings, 2:33 so that the status is more evident. 2:39 Let's use a switch statement. 2:53 Switch, and we'll check our listing, 2:56 get status, And our default, 3:01 Will be the panel default. 3:11 Now for our case, we check the premium. 3:16 We say panel-info, 3:19 and break. 3:29 Let's preview these changes now. 3:34 That looks much better. 3:39 We actually see the description, and the listings are clearly separated by color. 3:40 Let's try adding another listing. 3:45 Wonderful, let's go back to the index page and 4:15 remove the var_dumps. 4:20 One last feature I want to add is the ability to easily view the different 4:29 types of listing Because of the way we have things set up this is a fairly 4:34 minor change. 4:38 To change the status that is displayed, we just need to change our filter. 4:39 I actually have this ready to go for you using a get variable. 4:45 If the get variable status is set we filter the input and set the status. 4:48 We just need to add the links to make this easy to navigate. 4:55 Below our test, let's add a new list, 4:58 Our class equals nav nav-tabs And let's close the list. 5:07 For our list item, 5:20 we'll give it the role of presentation. 5:23 If, Our filter status, 5:34 Equals active, 5:43 Then we'll set the class to active. 5:49 Then we need a link. 6:00 And since this is our default, we're just gonna set it to index.php. 6:04 And we'll say Active. 6:12 End our link, end our list. 6:17 Now we're ready to loop through our statuses. 6:22 foreach ($directory- 6:25 getStatuses(), as $status). 6:32 Then we'll copy this list item. 6:45 Instead of active, we'll set this to our status. 6:53 And we're going to pass our status. 7:01 For the display, instead of just showing the status, 7:14 we're gonna use UC words for uppercase words. 7:18 And then status. 7:23 Let's preview this site once more. 7:26 Our listings are clean and 7:30 we can now easily click between different display options. 7:32
You need to sign up for Treehouse in order to download course files.Sign up