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.
Additional resources
In this lesson, you'll learn how to dress up the plain HTML that's being output in your Symfony app with a template layout using Twig's template inheritance feature. You'll learn how to use both block
and extends
Twig keywords to create, use, and re-use HTML layouts in your app. To explore more features in Twig, head over to the Twig Templating series.
Additional resources
In this lesson, you'll learn how to bring in CSS and JavaScript assets for use in the templates of your Symfony 3 app.
In this lesson, you'll learn how you can use Symfony 3 to create first-class APIs. We'll cover how to create endpoints, JSON controllers, and more.
PHP for Beginners Part 3
CourseWe already have a data source from PHP for Beginners Part 1 and PHP for Beginners Part 2 that makes our application dynamic. It reads and displays pet data, which happens to be stored in a file called pets.json. If we change something in this file, the site updates automatically. For a more complex site, however, we'll need to read and write a lot of data. So we're going to dive into the world of databases now and learn how to manage more data. This first tutorial covers database basics and how to connect and communicate with a MySQL database.
Additional resources
In this tutorial, now that we've connected to our database, we're going to learn the basics of SQL queries. You'll learn how to create databases, the tables that live in them, and how to do a basic SELECT query to retrieve information.
In this tutorial you'll get familiar with the INSERT and SELECT SQL commands to let you add and retrieve data from your database.
We're going to bring things together in this tutorial by finishing the basic queries of UPDATE and DELET, along with SHOW. Then we'll wrap things up by taking a look at the most popular MySQL GUI, phpMyAdmin.
Now that we understand the basics of a MySQL database and using SQL queries to talk with it, in this tutorial we're going to see how to talk to our database from inside our PHP code. You can download the sample code below.
To talk to the database, we first open a connection using a class called PDO. This returns an object, which we set to the $pdo
variable. In this tutorial we're going to talk a little more about what this means and how we use them. We'll also take a quick look at how this "new" object-oriented way of doing things is different from the old, deprecated functions.
YAML, which stands for YAML Ain't Markup Language, is a human-readable data serialization format that's been widely adopted in a variety of use cases in Drupal. Anyone wanting to write modules, or themes, for Drupal will need to understand YAML syntax. Even site builders are likely to encounter YAML at least in passing as YAML is the data-serialization format of choice for Drupal's configuration management system. Good thing it's pretty easy to learn even with the most basic of programming backgrounds.
This tutorial will look at the YAML data format and provide examples of how to write and read YAML. Starting with an introduction to the language's syntax and some of the strengths of YAML. Then looking at the difference between scalar data types like strings and integers, and collection data types like lists and associative arrays.
Since YAML in the Drupal world is read into PHP and ultimately becomes a PHP data structure that we can use in our own code we'll also look at how the YAML we write in a .yml file is represented in PHP data types. To do this we'll use the YAML Sandbox module that provides a handy textarea into which we can type YAML and have it parsed into PHP data structures.
Learning objectives
- Explain what YAML is and its strengths as a data serialization format
- Create scalar key/value pairs in YAML
- Create lists, and associative arrays using YAML collections
- Understand how the YAML you write is represented in PHP
Tips
- In Drupal, use the .yml extension and not .yaml
- Ensure your code editing application is configured to use spaces (preferably 2 spaces, as per Drupal coding standards), not the tab character when the TAB key is pressed. If you have tab characters in a YAML file within a Drupal environment, a fatal PHP error will be thrown and you'll see a White Screen of Death (WSOD).
- Copy and paste from an existing YAML file to ensure the formatting is correct, and edit from there.
Additional resources
- http://www.yaml.org
- YAML Sandbox module
- Find other tutorials and external resources related to YAML on our YAML topic page (Drupalize.Me)
To make it easier to control your app, configuration, like your database username and password, is usually isolated into its own file. In this tutorial we'll create a new file called config.php and see how to simplify our database information.
As we add more pets to the database, our query is going to return a lot of results. In this tutorial we'll take a look at how to control the number of results we get back from our query using LIMIT. We'll also end up introducing a security hole in our code, which we're going to correct later in this series.
In this tutorial we're going to add our $limit
variable as an optional argument to our get_pets()
function. We're using this variable in our if
statement, and we're going to look at different ways to supply "true" and "false" using data other than booleans. This allows you to pass in a value and still evaluate true/false. PHP has some conventions for what is true or not, and it's a good idea to understand what these are.