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.
In this tutorial we're going to create pages for each of our pets by using a query parameter. This is a bit of code that is added to the end of a URL to pass information to PHP. They look something like ?id=23
. On the PHP side of things we'll use the $_GET
superglobal variable to pull that data into our code.
Our last big piece to the puzzle is to create a function to query the data for just one pet. In the process of doing this, we're going to get a lesson in function scope, where each function is its own little universe and you only have access to the arguments passed in and any variables you create in that function. This can trip you up when you need to access that data from another function. In this tutorial, we'll get that all sorted out and finish up our get_pet()
function.
Both get_pets()
and get_pet()
contain an SQL query where one part of it is a variable. Whenever you have this situation, you’re opening yourself up for an SQL injection attack. In this tutorial we'll see how this works by exploiting the security hole, and then fixing it up with prepared statements. Prepared statements let us build a query where the variable parts are kept separate from the rest of the query. This will conclude our work for this section of the site and managing databases.
In this lesson, you'll learn how to generate URLs in Symfony 3 and use Twig's path()
function to output HTML links based on the name of the route.
Additional resources
In this lesson, you'll learn how to integrate ReactJS into the Twig templates of your Symfony 3 app. You will learn how to include page-specific JavaScript assets, include the ReactJS code, direct ReactJS to use the API you've built in your Symfony app, and generate URLs for dynamic JavaScript assets. With this lesson complete, you will have completed building a rich HTML page and an API endpoint to fuel some sweet JavaScript using Symfony 3.
Ready for more Symfony 3? Check out Symfony 3 Fundamentals: Bundles, Configuration and Environments next!
Additional resources
Bundles in Symfony 3
FreeIn this lesson, you'll learn more about the fundamentals of Symfony 3 and how to get access to more services for your app through installing bundles. If you haven't built your first app in Symfony 3 yet, head over to Joyful Development with Symfony to get up and running, then head back to this series and continue your Symfony 3 journey!
In this lesson, you'll learn how to use the new service that you installed through a bundle in the previous lesson.
In this lesson you'll learn how to configure and control how services from a bundle behave.
Additional resources
In this lesson you'll learn how to add a cache service to your Symfony 3 app.
In this lesson you'll learn how to further configure DoctrineCacheBundle in your Symfony 3 app.
In this lesson you'll learn about how you can set up configuration for your app depending on the environment—development, production or whatever else you might have.
Additional resources
In this lesson we'll continue to explore the configuration files for our "dev" and "prod" environments.
Additional resources
In this lesson you'll learn how to configure settings for specific environments. Here we'll disable caching for the dev environment, so that caching is enabled only for the prod environment.
Additional resources
In this lesson you'll learn about some special variables called parameters that are available in configuration files for Symfony. We'll explore already existing parameters as well as learn how to create a new parameter.
Additional resources
In this lesson you'll learn how to use the extra special parameters baked right into Symfony. These particular parameters can be super useful, so let's dive right in and learn all about special parameters in Symfony.
In this lesson you'll learn how to master route configuration loading and load the routes you want from certain bundles.
Ready for more Symfony 3? Check out the next series: Symfony 3: Level up with Services and the Container.
In this lesson, we'll explore what problems a services architecture can solve. You'll learn how services can unlock a bunch of powerful features for you in Symfony 3.
New to Symfony 3 or need a brush up on Symfony concepts? Check out these series first and then head back here to dive into Services and the Container.
Note: To set up the project and code along, see the instructions in start/README.md.