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:
- How Composer makes sharing awesome again
- Downloading the composer.phar file
- Creating the composer.json file
- Installing the external libraries
- Handling autoloading
- Understanding the composer.lock file
- The update versus install command
- The require command
- Storing in version control
Additional resources
- Composer website
- Packagist
- http://bit.ly/composer-dump-autoload
- http://bit.ly/composer-require-dev
- http://bit.ly/composer-min-stability
- http://bit.ly/composer-global-install
Also, check out our topic page on Composer for even more resources.
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.
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.
Additional resources
PHP Namespaces in under 5 Minutes (symfonycasts.com)
PHP for Beginners Part 2
CourseIn this second part of PHP for Beginners, you'll learn all about forms, form submissions, how this translates in the HTTP Request/Response world, and saving files to the disk. This series continues from PHP for Beginners Part 1, and we'll be expanding on that same project in this series.
In this tutorial we'll get things set up and ready to go by setting up our sample code, doing a quick review of the HTTP request, and creating a new page for the site with some navigation.
Additional resources
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.
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.
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.
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.
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.
Additional resources
Now that we've created a service, let's configure it. In this tutorial, you'll learn how to register your new service. We'll also be using Drupal Console to ensure everything is working as it should.
Note: The Drupal Console command container:debug
is now debug:container
.
Note: Drupal Console is no longer maintained. There are other tools and methods for getting a list of services in the container. See the tutorial Discover and Use Existing Services to learn more.
Additional resources
Discover and Use Existing Services
Dependency Injection and the Art of Services and Containers — Drupalize.Me
An Introduction to YAML — Drupalize.Me
In this lesson, you will learn how to get a Symfony 3 project started. First download Symfony and then follow along with this video tutorial.
Additional resources
Learn how to set up the IDE PhpStorm for Symfony 3 development. In this lesson, you'll install the Symfony plugin. You'll also want to install the PHP Annotations plugin in the same manner. Finally, you'll initialize a new Git repository on your system.
Additional resources
In this lesson you'll build your first page in Symfony 3. Be sure to download the code below so that you can follow along.
Tip: You should also find and install the PHP Annotations plugin. That will give you the awesome annotations auto-completion that you'll see in the video.
Additional resources
PHP Namespaces in 120 Seconds
PHP Namespaces Support in PhpStorm
PHP Annotations plugin for PhpStorm
In this lesson, learn how to make use of routing wildcards in a Symfony 3 app.
Additional resources
Be careful when rendering direct user input (like we show here)! It introduces a security issue called XSS. Read more about XSS here
In this lesson, learn how to use services and other useful objects like the service container in Symfony 3.
In this lesson, you'll learn how to find services you might want to use in the container by listing them.
In this lesson, you'll get a crash course in Twig. Covered here are the "say something" syntax, the "do something" syntax and for
loops. For broader coverage of Twig and the amazing things you can do with it, head over to the Twig Templating series.