7 days of WordPress plugins, themes & templates - for free!* Unlimited asset downloads! Start 7-Day Free Trial

Next lesson playing in 5 seconds

Cancel
  • Overview
  • Transcript

3.3 Create the Dream Viewer Page

We can now write users and their dreams to a text file behind the scenes. But this only tells half of the story. We need to be able to programmatically read the data from the file. Before we start that process, let's create another PHP page that we will use to display the data to the end user.

3.3 Create the Dream Viewer Page

Now that we're actually able to successfully write the dreams to a file, let's start to build out the infrastructure to allow us to actually read these dreams and display them on a page. So the first thing that we wanna do is create a new page. So we're gonna create a New File, and let's call this one viewer.php. And then once again in here, we're gonna have an html file. We're gonna use html:5 again. And once again, we don't need all of this extra stuff in the header, but we'll give the title. We'll call this one the Dream Viewer. And what we wanna do in this case? Well, we wanna do some similar things that we did the actual index.php page. We wanna be able to have a function that's gonna handle the reading of the data from the file, and then actually displaying it. So lets kinda put those two things together here. So lets add another h2 and you could do this in PHP, or you could do it in straight html. I'm gonna do it in html, and we'll simply say here, Here are all the dreams. Then underneath it we're gonna create a list of combinations of the names and the dreams, and we'll just do that with a dl. Will do that with a definition list here Where we'll have terms and definitions, and we'll wind up filling this out with some stuff that we get from PHP. So we're gonna just put our PHP block in here, and we'll wind up calling something and doing something in here. And what do we wanna call? We wanna be able to call a function that's gonna be able to handle this reading for us. So we'll call read_dreams. and we don't have to pass anything in, and then we'll have to fill that out, right? We wanna be able to fill that out but in order for this to work we're gonna have to wrap this in a PHP tag just like that. So now we have our read_dreams function, and we are going to use that read_dreams function down here in our actual codes. Let's go ahead and save this. So what's gonna wind up happening is we'll have to go to the viewer.php. And then we'll see a list of all of the names and definitions, where all the names and dreams of people right here. So now we have the basic layout of what our code is gonna be. So over the next couple of lessons, we're gonna start to fill this out and see how we're gonna read the dreams. And ultimately, how we're gonna display them to the end user.

Back to the top