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.
In this lesson, we'll move code out of the Controller and into a new class. You'll learn how to create this new service class and refactor the code that you took out of the Controller to work in this new context.
In this lesson, you'll learn about the dependency injection workflow and refactor our code to inject the dependency.
In this lesson you'll learn how use type-hinting to make your code more portable—and readable, too.
In this lesson, you'll learn how to register your service in the container so that you can can access it in your class.