More with ManyToMany: Avoiding Duplicates
…an error!
SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry
‘4-4’ for key ‘PRIMARY’
Our User is once again added as an attendee to the Event. And when Doctrine saves,
it tries to add a second row to the join table. Not cool!
Adding…
Symfony Overlord: The Service Container
…With such a tiny list, it’s easy
to spot the entity manager service: doctrine.orm.entity_manager. This
is the “name” of the service and we use it to get this object out of the
service container.
We’ve been getting the entity manager…
Inserting and Querying Data
…the error straight
from MySQL saying that the details column can't be null.
SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'details' cannot be null
So Doctrine assumes by default that all of your columns should be set to NOT NULL
when creating the table…
Code Generation FTW!
…we need a CRUD for the Event entity.
Want to use Doctrine to generate a CRUD? Yea, there's a console command for
that doctrine:generate:crud:
php app/console doctrine:generate:crud
This inquisitive command first wants to know which entity we need a…
Adding Outside Bundles with Composer
…are dummy data we put into the database.
When we started the project, we downloaded the Symfony Standard edition:
our pre-started project that came with Symfony and other tools like Doctrine.
Unfortunately, it didn't come with any tools for handling fixtures.
But we…
Introduction
…some of the most difficult areas of Symfony, like security, forms, and
some serious Doctrine topics. Some of this stuff will look pretty tough at
first, but that’s just because we’re taking your Symfony foo up to the next
level. When you finish…
Entity Security
…one:
# app/config/security.yml
security:
I’m just inventing the our_database_users part, that can be anything.
But the entity key is a special built-in provider that knows how to load
users via a Doctrine entity.
Yea, and that’s really it…
Saving Users
…class (LoadEvents.php) into the UserBundle, rename it to LoadUsers,
and update the namespaces:
// src/Yoda/UserBundle/DataFixtures/ORM/LoadUsers.php
namespace Yoda\UserBundle\DataFixtures\ORM;
use Doctrine\Common\DataFixtures\FixtureInterface;
use Doctrine\Common\Persistence\ObjectManager;
use Yoda\UserBundle\Entity\User;
class LoadUsers implements FixtureInterface
…
Adding Dynamic Roles to each User
…database, these are stored as a JSON string. Doctrine takes care of converting
back and forth between the array and JSON.
Now, just update the getRoles() method to use this property and add a
setRoles method:
public function getRoles()
{
}
public function setRoles(array $roles)
{
}
Cool…
Repository Security
…Serializable
Note
Actually, if you don’t set the repositoryClass option, Doctrine
just gives you a base repository class for that entity.
Repositories are where query logic should live. We could create methods like
findActiveUsers, which would query the database for users that have a…
The UserProvider: Custom Logic to Load Security Users
…logging in now! Ah, a great error:
The Doctrine repository “Yoda\UserBundle\Entity\UserRepository” must implement UserProviderInterface.
The UserProviderInterface¶
Without the property, Doctrine has no idea how to look up the User. Instead
it tries to call a method on our UserRepository. But for that…
User Serialization
…object hidden in our entity causes serialization to fail.
The entity manager contains a database connection and other information that
just can’t be serialized.
Using the Serializable Interface¶
We need to help Doctrine out. Start by adding the Serializable
interface to the User class…
Custom Validation, Callback and Constraints
…Event entity
that looks like this (with some extras, like getter and setter methods):
// src/KnpU/QADayBundle/Entity/Event.php
namespace KnpU\QADayBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
@ORM\Entity(repositoryClass="KnpU\QADayBundle\Entity\EventRepository")
/
class Event
{
@ORM\Column(name="id", type="integer")
…
Symfony Live Lille 2019 (French)
…sur Symfony. Une dizaine de speakers sont venus présenter des sujets sur Symfony (évidemment), mais aussi Mercure, Doctrine, API Platform ou encore React et Redux ainsi que des bonnes pratiques sur les meilleurs bundles et outils pour vos applications Symfony, et d’autres passionnants sujets !…
Starting in Symfony2: Course 1 (2.4+)
…from
the ground-up, touching on and discussing the most fundamental parts
of the application. Specifically, we'll cover:
Installation, Git and Setup
Composer
Routing
Controllers
Introduction to the service container
Twig
Doctrine
Server setup
Code generation
Fixtures & external libraries
And other tips and tricks
Lean and Mean Dev with PhpStorm (for Symfony)
…lot of the grunt work out of your coding and help
you get things done faster:
Get the life-changing Symfony plugin
Auto-complete namespaces (please stop typing them)!
Tricks for annotations, Doctrine, forms, Twig and more
Refactoring
Live Templates
Fast navigation
Symfony service integration
...…
Starting in Symfony2: Course 3 (2.4+)
…Plus a ton more!
Highlights:
Doctrine relations, metadata, and the JoinColumn
ManyToMany relationship that's bidirectional, owning versus inverse side and why that matters
Loading fixtures with shared data
Creating shortcuts with your very own base controller!
Doctrine extensions: timestampable, sluggable
Ajax: returning Json from…
Upgrading to Symfony 8
…edges that pop up along the way. And along the journey, we’ll tackle one of the biggest ecosystem shifts: upgrading Doctrine to take advantage of PHP 8.4’s native lazy proxies - goodbye generated proxy classes, hello simpler, faster magic.
Whether you’re maintaining…
Maker Bundle: Let's Generate Some Code!
…same thing. Thanks
to the new bundle, we have a ton of commands that start with make! Commands for
generating a security system, making a controller, generating doctrine entities to
talk to the database, forms, listeners, a registration form.... lots and lots of
stuff!
Let…
Inheritance with Twig
…if statement... like if ship.type == 'freighter', but that would get
messy really fast. Instead, let's use Twig template inheritance. Twig Template Inheritance
with Doctrine Inheritance, I love it!
First, in the templates/starship directory, create a new teaser
directory. This will be…
x
1000+