Example Lesson Videos - Advanced PHP for Drupal 8

  • Lesson Notes
  • Playlist
  • Transcript
Lesson Notes
These are two example lesson videos pulled from our Advanced PHP for Drupal 8.

See Full Course Syllabus and Schedule

Example Code For This Course

All the example code you see me using in this course is available as a git repository. This allows you "checkout" different versions of the code to move to any point in the course. Your primary assignment each week is to follow along with creating the modules you see me create in the lesson videos. You have two ways you can do this. Personally, I prefer to copy and type out the programs I see on screen, because I find it helps me remember things better. However, this can be fairly time-consuming, so there is a second option. Since I have provided many different versions of the code in the example git repository, you can watch the videos, and when you get to a checkout point (there will be an on-screen prompt), checkout that version of the code, read through it, and run it to confirm you understand what you've just watched. That will take less time, but I will leave it to you to decide how you learn best. Be sure you perform the clone operation in the correct folder, depending on whether or not you want to copy the code yourself or just use the example code to follow along. I discuss the appropriate locations in the code repository video.

Frequently Asked Questions

Do the lesson videos play on iPads and iPhones?

Yes, they work on both desktop/laptop computers and iOS devices.

How can I ask questions or get help?

You can ask questions about the lesson or get help with your assignment by posting to the class discussion forums and attending the weekly live Q&A sessions with the instructor. (online via webinar software)

Do I need to have my own website or hosting account to work on?

No, we will provide you with a development environment you can install on your computer. Installation and configuration of the local development is covered step-by-step in course lesson videos.

Before we get into the details about PHP programming, we should take a minute to just talk more of on a fundamental level like what is PHP? How does it operate? So PHP stands for PHP Hypertext Preprocessor. It's a server-side scripting language designed to produce dynamic web pages. It can do other things as well, but dynamic web pages is its chief mission. It's open source. It was created in 1995, and it was originally designed as a way to insert small bits of dynamic content into a web page. So in 1995, most web pages were just standard html pages, static html. And so PHP was a way that, in the middle, let's say of a static html page, you could have some small dynamic snippet that might change every time you loaded the page. That's really where PHP came from. And it was very function-oriented and grew organically. So if somebody needed a function, for that purpose somebody needed a function that did X or a function that did Y, and so it got added to the language. But there wasn't a whole lot of top-down sort of planning in that process and so PHP got a lot of criticism or gets a lot of criticism that it can be very inconsistent. So when you look at function names and function signatures, they're often very different. Like I said, they don't show a lot of consistency between how each one works, and they don't sort of follow a lot of the best practices of object-oriented programming that you might learn if you went to have a computer science degree. And so a lot of people have said that oh well, PHP is not a real language. It's a terrible language. A lot of people say that. If you google around them in the internet, you'll have no trouble finding that. However, there is a modern PHP movement that advocates for a PHP style of programming that is much more consistent, internally consistent in how it operates as well as it's being consistent with object-oriented best practices. And so this modern style of PHP, this object-oriented PHP is the style that we will eventually be leaning. However, we'll have to learn some of the simpler form of PHP first, the function-oriented let's say PHP and then we'll move into some of the more object-oriented because it's a little bit more complex, but personally, I can say I like programming that way a lot nicer and in order to operate in the PHP world today, you really need to understand that modern PHP, as well as the simpler form. So PHP, despite all of its inconsistencies and its history, it does power 75% of websites that are using server-side programming. It's the most used open source software in enterprises and big companies use it. Facebook is all built on PHP. Wikipedia is the same. The reason why enterprises and big businesses use it is PHP is pretty easy to learn, and it focuses a lot on solving common problems versus being sort of an academically pure language. All right. So I said that PHP uses the server-side scripting language. So what does that mean exactly? Well, it means that we have two actors, at least two actors here in this. When are executing PHP code, we have a client which I have listed here as the browser and then we have some server somewhere and it may be a physical server all over the internet, it may be a virtual machine that's running either over the internet or on your own computer, but you'll have something distinctly separate that is the server and the server is usually made up of sub components. So I've listed a few here, the web server and the database server. The database server is... not all PHP programs would have one, but many PHP programs will store their data in the database in which case they would have MySQL, PostgreSQL, SQLite, something like that as a database server. But the chief actor will be the web server which is made up of two components. There's PHP and then there are some web server program. Now, I've shown Apache here; another popular choice is Nginx and there are many others, as well. Your web server program coordinates with PHP to sort of functionally deliver the... and possibly database server to functionally deliver those dynamic pages. And so let's take a look at how does that work in sort of a step-by-step. So let's imagine that we're loading up some blog page on the internet. It could be anything, any dynamic page on the internet. Your browser in step 1 here is going to make a request to the server, to the web server. That is going to talk to Apache in this particular example but it could be Nginx or something else, as well. It's going to talk to web server and if the file... the web server is going to go to the hard drive and retrieve whatever file it is you've asked it to load. If that file happens to be a static file like let's say it's an image, JPEG, then it can actually bypass, it can jump ahead all the way to step 6 and just send that JPEG right back to you. All right. So if you happen to be trying to view an image, you're not going to ever... PHP is not going to be involved in that transaction. However, if what you're trying to load is a PHP file, now a PHP file is just a text file, but it's got some special tags in it and has a special extension, .PHP that tells Apache that this is a PHP. This is not just a text file. So don't send it straight back. You need to allow PHP to work with this and return a result. So when Apache detects that it has a PHP file, it will send that over to PHP and PHP will do three different things. It will first compile the file so that means take that text file and turn it into binary code, so 1's and 0's. That's the code you can execute on the CPU or whatever. So then it will execute that file and during the execution, it might access other resources. For example if it is a blog like either a WordPress or Drupal blog, it would call out to the database during that process, probably, during the execution stage as it sort of builds the result. And then in sort of stage 4c, let's say, it will take that result which will be html text. So html tags plus text and it will return it back in step 5 to the web server and the web server will pass that along back to your browser where you get the result as html and then your browser will render that into the blog that you see when you hit it with your browser. All right. So in order to do development work with PHP, we need to replicate this sort of environment on your local computer, on your desktop or your laptop. And to do that, we are going to use some software called the BitWisdom Development Stack. This is a development platform that I built and it's based around a Linux virtual machine that you run on your own computer. So it'll be... it's like having your own Linux server running on top of... a virtual server running on your own machine. It uses Vagrant and Virtualbox to power that virtual machine system. Virtualbox is a software; it's a virtual machine container. It's actually what runs the virtual machine and then Vagrant is some software that allows you to write sort of configuration scripts for building virtual machines and executing them, sort of bringing them online and shutting them down. And so we'll be using both of those tools along with some scripts that I've pre-written in order to get this development stack up and running. And that stack will basically replicate these features that we have in this picture. So it has MySQL, it has Apache and has PHP. It doesn't have PostgreSQL or SQLite but we don't need that. We only really need one of the database servers. All right. In addition to the BitWisdom Development Stack, we're also going to be using NetBeans. NetBeans is a free open source integrated development environment or IDE. An integrated development environment is like a glorified text editor. At its heart, it just allows you to edit text files. However, it has a lot of development tools built in. So for example as you're... because remember, all these PHP files are just text files, at least, when we edit them. Then they get compiled by PHP. But the text files we edit, when you edit them in an IDE, it will do some things like it will change the color of text so that you can tell... so it'll help prevent errors. It'll highlight things that things are mistakes. It will also do auto completion based on PHP syntax so it helps you in that regard to avoid mistakes. And then I think best of all it has a debugger built in. So this allows you to go and execute your code one line at a time and actually watch what happens so that it helps you figure out when you've made a mistake where that mistake is. And so these are common features of integrated development environments. And so NetBeans is the one we're going to use with this course. And then finally, you will need a web browser for doing the coding and debugging. I recommend that you do not use Internet Explorer for this purpose. It's just not that great. It doesn't have some of the features of the other browsers for development work. Better would be either Google Chrome or Firefox with the Firebug extension. Both of those are common choices for doing development work or web development work. All right. In the next couple of videos, I'm going to show you how to set this up both on a Mac computer and on a Windows computer. And then we'll have another video where I'll actually walk you through all of these tools and explain like what features these have. So let's watch the installation, and then we'll come back and we'll go through with the details of how these tools work.