1000 search results

Using a Test Database

…as the default. Once we do that, we can setup the test environment to use a different database name. Open config.yml and copy the doctrine configuration. Paste it into config_test.yml to override the original. All we really want to change is dbname…

6:52
Symfony: Keep it Simple with @Route and Templates

… So let’s finish this page. It should be fairly straightforward: we’re going to use Doctrine to query for all the posts and then pass them into a template: /** @Route("/posts") / public function indexAction() { } Now, notice that my template name does not have any…

8:42
Making Fixtures Awesome with Alice

…files, and the same DoctrineFixturesBundle that we were talking about before. This is a really nice combination because it's going to mean that we can still run our normal php app/console doctrine:fixtures:load. But after that, instead of writing raw PHP code…

12:23
Interrupt Symfony with an Event Subscriber

…a lot more interesting. You can already see where our controller is called, and under the controller you can see the Twig template and even some Doctrine calls being made. Before and after that, there are a lot of event listeners - you notice a lot…

8:40
Making an Argument Available to All Controllers

…which works via a listener to kernel.controller, grabs the id off of the request attributes, queries for a Post object via Doctrine with that id, and then adds a new request attribute called post that’s set to that object: // Summarized version of ParamConverterListener…

3:57
Dependency Inject All the Things

…the router service. So how can we get the router service inside EventReportManager? You know the secret: dependency injection. Add a second constructor argument and a second class property: // src/Yoda/EventBundle/Reporting/EventReportManager.php // ... use Doctrine\ORM\EntityManager; use Symfony\Component\Routing\Router; class…

3:14
Using PHPDoc for Auto-Completion

…better than nothing. But first, update your test database for our latest schema changes: php app/console doctrine:schema:update --force --env=test We need this because we configured our project in episode 2 to use an entirely different database for testing. ./bin/phpunit -c app/

1:26
Using the ManyToMany so Users can Attend an Event

…that we show 1 attending means that the database relationship was stored correctly. We can prove it by querying for the join table: php app/console doctrine:query:sql "SELECT * FROM event_user" Yep, we see one row that links our user to this event.…

4:53
Your Very First Service

…we don’t extend anything and we don’t magically have access to this Doctrine object. The code inside EventReportManager is dependent on this “doctrine” object. Well, more specifically, it’s dependent on Doctrine’s entity manager. The fix for our puzzle is to “inject…

4:42
Configuration Loading and Type-Hinting

…mind trick ... I mean auto-complete the use statement for me. It’s lazy, but it almost always works: // src/Yoda/EventBundle/Reporting/EventReportManager.php // ... use Doctrine\ORM\EntityManager; class EventReportManager { } If you’re not too comfortable with this, don’t worry. This is optional…

2:01
Welcome to Symfony!

…requests, responses and templating. Get comfortable with a few extra tools, like Doctrine for dealing with the database and code generation tools. And the real reason you are here, to learn enough best practices and tips to impress your friends at a party. Ready? Let…

2:51
Server-Side Validation

…It takes two options: the field that should be unique followed by a message. Add a constraint for both the username and the email: // src/Yoda/UserBundle/Entity/User.php // ... use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; /** @ORM\Table(name="yoda_user") @ORM\Entity(repositoryClass=…

4:18
Upgrading to 2.2

…replace the core Symfony libraries, and not any custom lines you may have added. In this case, the doctrine-fixtures-bundle is custom, so I’ll leave it alone: "require": { }, Also, be sure you have the minimum-stability set to alpha. As Stof points out…

3:46
FOSUserBundle

…stored in the database. Let’s create a new bundle called UserBundle to house the new entity. Instead of using the doctrine:generate:bundle task, I’ll just create a UserBundle and make sure there’s a properly-named bundle class inside. Don’t forget…

13:15
How to handle dynamic Subdomains in Symfony

…differences here are a bit subtle. For example, the baseHost is now stored in a property and we can get Doctrine’s repository through the $em property. We’ve also replaced the createNotFoundException call by instantiating a new NotFoundHttpException instance. The createNotFoundException method lives in…

11:43
Querying Classes

…setParameter(), for the second argument, use $this->getEntityManager()->getClassMetadata(Scout::class). This returns a special metadata object for the Scout class and is what Doctrine needs to properly handle the INSTANCE OF operator with parameters. Refresh the browser... and nice, just the scouts again! Try…

5:48
Installing API Platform

…s empty because we don't, ya know, actually have an API just yet, but this is going to come to life very soon. Next: Let's create our first Doctrine entity and "expose" that as an API Resource. It's time for some magic.

7:29
Multiple Submit Buttons

…it also guesses field type options. For example, if a Doctrine entity property is nullable: true like for this notes field: Then Symfony will automatically make it optional. And the reverse for the other fields, the required HTML attribute will be added if the field…

6:45
Autoconfiguration

…configuration, and environments. We are powerful! No, unstoppable. In the next tutorial, we'll introduce Doctrine - the industry standard way to work with databases in PHP. Until then practice. Go build something - anything - and tell us about it. And if you have any questions, thoughts…

8:36
The Serializer

…methods. Cool! This will also cause the column in my database to change... so spin over to your console and run: symfony console make:migration I'll live dangerously and run that immediately: symfony console doctrine:migrations:migrate Done! Thanks to that rename... over in…

9:08