PHP Basics

Header, Footer, & Details

Maximiliano Firtman

Maximiliano Firtman

Independent Consultant
PHP Basics

Check out a free preview of the full PHP Basics course

The "Header, Footer, & Details" Lesson is part of the full, PHP Basics course featured in this preview video. Here's what you'd learn in this lesson:

Maximiliano modularizes the application by creating header and footer include files for the page. This way the common headers and footers can be reused on each page of the application. The details page is created and the index page is refactored to include a list of exhibits.

Preview
Close
Get $100 Off
Get $100 Off!

Transcript from the "Header, Footer, & Details" Lesson

[00:00:00]
>> Maximiliano Firtman: Okay, let's execute this. I don't know what will happen.
>> Maximiliano Firtman: So let me start here. Okay, I'm able to open database file, and here I have the path, blah. Look at this, its trying to it said it's the file, trying to see if I am seeing it's here the constructor has to do there is a problem with the constructor okay it cannot open the database file so this is the problem I'm in the DB and I'm using dot dot I'm not sure if you remember when I type that I ask should I do the dot.

[00:00:40]
We'll see. Well, this is the moment to see. So, it says, well, we are in DB, so we are going one level up to get into data, which seems like a good idea, but seems like it's not working. Why is that? Because, actually, our entry point Index PHP.

[00:01:03]
Doesn't make sense, so what happens if I do this instead? Remember, include is like copy and pasting. We're not talking about modules here. These are not modules, just including the file. We are including the DB file in Index PHP. So then this code is being executed in the context of index PHP.

[00:01:26]
Does it make sense? So then I can try again. And well, we are getting better. So we are getting something, but it's not yet what we are expecting. So it says trying to access array offset on integer on the index line 32. Okay. By the way, I'm not ready with the index, but it's complaining here because it doesn't have a description, which I think it should be right.

[00:01:56]
So first, something that I can do is I can do a bar dump of exhibits to see, okay, what do we have here? Okay, so if I refresh, this is what we have. We have an array of four elements, okay? The four elements are directly this. So, I'm not sure if you realize what's going on here I'm getting only one element it's an array of four it's only one element only one exhibit let's try to understand what's going on before moving on so I don't want to see this so I will actually delete that part because I actually wanna do a master detail so when I get into a detail.

[00:02:40]
So I, I'm going to delete the article. What I want actually is a list. I will create a UL outside and I will close the UL here like that. And I'm going to create list items. Okay? Make sense? So I added the UL. And DLI. Do you understand why?

[00:03:06]
I just wanna list the titles, just that I don't wanna see the rest. Let's go back to the SQL Light 3 implementation that we have here. fetch array, this. I tried to see, I'm not sure if VS Code will give me, yeah, I wanna, will give me the answer.

[00:03:29]
It says, fetches a result row as an associative or numerical array. So if you look here, it fetch array is giving me just one row.
>> Maximiliano Firtman: One row, not all the rows, can you see that? Let's try to analyze the solution in this way, just because we have this one that is working let me do this let me go and grab from here let's change this to execute one.

[00:04:06]
One what? One result. Okay, so I want to receive one result. So we know that it works for that situation, for one. And what are we going to do now? I'm going to take that index PHP and I'm going to make another copy. And by the way, copy and pasting doesn't seem like a good idea, but you will understand what we are doing in a second.

[00:04:31]
I will call this details PHP, Okay? But can you see that we have always the same HML as a header, the same footer, and we are copy and pasting, every page has the same header and footer. Do we have any other solution for that? Can you think on any other solution instead of just duplicating the whole design?

[00:05:01]
>> Maximiliano Firtman: Copy to an import? To an include. Include? Yeah, we can use includes. So for example, I can take,
>> Maximiliano Firtman: Maybe can be here to the main, this part. I will cut that part completely I will create a new file, paste it as header. Sometimes we use a different ink, this is pretty common, suffix or prefix, saying include.

[00:05:37]
So you know it's an include. It's something for being included, okay? So then in details PHP here you open and you say I wanna include here the header ink PHP, okay? And then, okay, that's all. And well, something to the end, actually the footer is very simple here, but let's do that for the first as well so I'm going to take that and I'm to save it as footer ink.

[00:06:11]
Does it make sense? Kind of? Would you usually put those all in their own folder, the includes? We can also create the folder for includes, yeah Sure. So now every page should have the include here and there. This is, let's say it's an old way to do this, to be honest, right?

[00:06:33]
So it's not really the best way. The way that I like is to actually do the reverse operation. Great idea of a master page. So, I create the HML, and I say here is the placeholder for the data. But PHP doesn't have that incorporated, so you need to program that yourself, the idea of a master page.

[00:06:56]
Of course, if you're using a library or a framework, typically they have that. You define a template that will be your master page template, and then you change that, okay? Does it make sense? Any question?
>> Maximiliano Firtman: No.
>> Maximiliano Firtman: So now, I can do the same for index PHP.

[00:07:21]
So, I can delete everything. From here there, I paste it. Remember that include is just a copy and paste, so that's why it should work. The advantage is now I can also change the indentation if I want. So, it gets back simpler indentation now, because now every page has only the part that belongs to that page and nothing else, okay?

[00:07:52]
So I think that that's that's pretty cool.

Learn Straight from the Experts Who Shape the Modern Web

  • In-depth Courses
  • Industry Leading Experts
  • Learning Paths
  • Live Interactive Workshops
Get Unlimited Access Now