Promotion ended
Sorry! This promotion has now ended. But please subscribe to our newsletter, and we'll notify you of future promotions.
Ready to get up to speed on current PHP tools and techniques? This week we're excited to provide to our wonderful members more new PHP videos from our partners over at KnpUniversity, a leading provider of PHP and Symfony video tutorials. All of this week's tutorials are also completely FREE!
Welcome to the wonderful world of Composer, the Dependency Manager for PHP! In this tutorial, you'll learn how to install and configure Composer and use it to integrate third-party libraries into any PHP project. We'll walk through:
Also, check out our topic page on Composer for even more resources.
We’ve already created our first service and used dependency injection, but one problem with the FriendHarvester is that we’ve hardcoded the SMTP configuration inside of it. What if we wanted to re-use this class with a different configuration? Or what if our beta and production setups use different SMTP servers? Right now, both are impossible! In this tutorial we're going to see how we can also inject configuration or an entire service. In the end we're going to inject the entire SmtpMailer object and build an interface for it. Through this process we'll make our code more flexible, since it will be able to accept any object that implements MailerInterface.
To learn how to apply these concepts in Drupal 8 module development, check out the Module Development Essentials series, starting with Understand the Service Container.
Sharpen your object-oriented skills by exploring the ideas and reasons behind dependency injection. This simple principle separates developers who write functional code from those that are able to build great, and maintanable applications. In this series, we'll see dependency injection in action, why it's important, and how it relates to services and service-oriented architecture. We'll also refactor our demo application to use a dependency injection container, using a fantastic—but simple—container called Pimple.
In this tutorial, we’ll be coding with a real example where we create a simple app to help people give their money away, we’re calling it SendMoneyToStrangers.com. We’ve already bootstrapped a small app, which you can download and use if you want to follow along. It uses an SQLite database, so if you don't have that set up, you can grab the database and find installation instructions on the SQLite site. Once you SQLite, you will install the app from the demo code we are providing. We will also be using Composer to make it easier to get Pimple when we need it. If you are not familiar with Composer, you can watch the short tutorial The Wonderful World of Composer to get up and running.
SQLite site
The Wonderful World of Composer tutorial
Pimple
To learn how to apply these concepts in Drupal 8 module development, check out the Module Development Essentials series, starting with Understand the Service Container.
Our project now has services, an interface, and is fully using dependency injection. Nice work! One of the downsides of DI is that all the complexity of creating and configuring objects is now your job. This isn’t so bad since it all happens in one place and gives you so much control, but it is something we can improve! If you want to make this easier, the tool you need is called a dependency injection container. A lot of DI containers exist in PHP, but we're going to use Composer to grab the simplest one of all, called Pimple. (If you are unfamiliar with Composer, you should watch The Wonderful World of Composer tutorial.)
The Wonderful World of Composer
Composer download
Pimple
To learn how to apply these concepts in Drupal 8 module development, check out the Module Development Essentials series, starting with Understand the Service Container.
Still not quite comfortable with PHP 5.3 namespaces? No problem! Give us 120 seconds and we'll introduce you to all the crazy characters ("namespace", "use" and "\") and show you how they work.
PHP Namespaces in under 5 Minutes (symfonycasts.com)
Our app is small now, but as it grows, the app.php file will get harder and harder to read. The best way to fix this is to separate each different chunk of functionality into different PHP classes and methods. Each of these classes is called a “service” and the whole idea is sometimes called Service-Oriented Architecture. In this tutorial you're going to create a new service, and learn about different ways to access external objects from a service. Then, we'll set up our app to use dependency injection to get the job done right.
Service-Oriented Architecture
To learn how to apply these concepts in Drupal 8 module development, check out the Module Development Essentials series, starting with Understand the Service Container.
Now it's time for you to use dependency injection containers in your own projects. In this tutorial we talk briefly about some other containers out there you might want to check out.
It is claimed that "every HTML table in Drupal 8 is responsive." What this actually means is that tables in the Drupal 8 admin UI are responsive and also that in Views, if you select a Table format, you have the opportunity to prioritize columns that will hide upon reaching narrower breakpoints. The strategy that is employed is that of adding "priority" classes to table cells and a "responsive-enabled" class to the table tag. At a tablet breakpoint, the "priority-low" table columns will hide and at the mobile breakpoint, the "priority-medium" columns will also not display.
You want to learn HTML and CSS, or maybe you just need a refresher on the current state of web technology—where should you start? This is a question we get asked a lot at Drupalize.Me. Our theming and module development videos often assume that you're familiar with basic HTML and CSS, so here is a list of our favorite resources.
In this week's podcast, Episode 48: Demystifying the Sprint, Kyle Hofmeyer talks with Cathy Theys (yesct), Michael Schmid (schnitzel), and Emma Karayiannis (emma.maria).
Drupalize.Me is looking for a Drupal trainer and developer to join our team.
Sorry! This promotion has now ended. But please subscribe to our newsletter, and we'll notify you of future promotions.
We're delighted to release another installment of PHP for Beginners videos from our amazing partners over at KnpUniversity. In these video tutorials, you'll learn all about HTTP responses and requests and step-by-step, how to process a form using php and JSON. Leanna takes you under the hood of a web page, showing you what information is being passed along and how you can make use of it in your PHP script.
We can now read the POST data from our form, but we can't really do much with it long term. We aren't saving the information anywhere. In this tutorial you are going to learn how to update our pets.json file with new information every time the form gets submitted. Since this is an important file for us to be able to use and read, we'll also quickly look at how to keep the human-readable formatting in place as we make our updates.
In this tutorial we will work with the PHP $_POST
variable, along with the $_SERVER
variable to capture the information from our form. We'll need to make sure our code is specifically looking for POST data, instead of GET, by using some logic.
Our form is working well now, and to finish up, in this tutorial we're going to clean up and reorganize our code a little bit by moving things into a new custom function, called save_pets()
. This won't change how the form works, but moving logic into functions gives us two advantages, re-usable code, and making it clearer what the code we've written does, and is intended for.
As you use your form, you'll notice that after you submit the form, you just keep seeing the form again. If you keep submitting it, you'll end up with a bunch of duplicate records. That's no good. In this tutorial you will implement a redirect on the form submission to take the submitter to the home page, instead of back to the form, using the header()
function. We'll explain what exactly a header is and how that relates to our HTTP requests.
In this tutorial we're going to leave PHP alone for a second and put together some good old HTML to create a form with name, breed, weight, and bio text fields. Once we create our form, we'll explain how forms get submitted over HTTP, and the difference between POST and GET requests.