SymfonyCasts's Avatar

SymfonyCasts

@symfonycasts.com.bsky.social

Injecting Unicorns and Rainbows back into learning PHP // The official way to learn Symfony: http://SymfonyCasts.com

651 Followers  |  5 Following  |  101 Posts  |  Joined: 02.11.2024  |  1.5282

Latest posts by symfonycasts.com on Bluesky

Preview
Pushing & Pulling Translations Our "Space Bar" project on Crowdin is all set up and configured for our app's locales. Let's push up our translations! At your terminal, run: """terminal symfony console translation:push """ Ok, all our...

We've successfully pushed our English translations up to @Crowdin.bsky.social . Merci beaucoup! now, let's automatically translate and pull them back down!

04.08.2025 09:01 β€” πŸ‘ 4    πŸ” 1    πŸ’¬ 0    πŸ“Œ 0
Preview
Translation Providers So far, we've mostly focused on translating our site from English to... English... What about French and Spanish? We've talked a bit about how we can manually send our "messages.en

For a course about translations, we really haven’t done much "translating" yet. That’s kinda important! Symfony has integrations with a few different Translation Provider services. Let’s look at @Crowdin.bsky.social, and see how it works!

01.08.2025 09:01 β€” πŸ‘ 4    πŸ” 1    πŸ’¬ 0    πŸ“Œ 0
Preview
`translation:extract` Command So far, we've been creating translation keys and manually adding them, and their values to "messages.en

The translation:extract command automates pulling missing translation keys from your PHP and Twig files. But it also has a secret, secondary purpose... Let's check it out! πŸ•΅οΈ

31.07.2025 09:01 β€” πŸ‘ 1    πŸ” 1    πŸ’¬ 0    πŸ“Œ 0
Preview
Installing PHP and Symfony CLI Locally The Symfony CLI makes local development a breeze - but it works best when PHP is installed directly on your machine. Let's walk through setting up PHP (plus common database extensions) and the…

The SymfonyCLI makes local development a breeze - but works best when PHP is installed directly on your machine. Let's walk through setting up PHP (plus database extensions) and the SymfonyCLI on macOS/Linux/Windows so you're ready to start building Symfony apps. symfonycasts.com/blog/install...

30.07.2025 09:02 β€” πŸ‘ 4    πŸ” 1    πŸ’¬ 0    πŸ“Œ 0
Preview
Debugging & Linting Translations Did you finish your homework? Don't worry, neither did I! Let's bike shed that for now and look at debugging translations. This'll be helpful for that homework anyway! ## Web Debug Toolbar On the English...

I'll admit it, mistakes are going to happen, translations will be missed! Let's look at the tools Symfony provides to help find these and how you can prevent missing translations from making it to production.

30.07.2025 09:01 β€” πŸ‘ 1    πŸ” 1    πŸ’¬ 0    πŸ“Œ 0
Preview
HTML in Translations Here's another complex scenario. On our homepage, scroll down to the footer

HTML in your translations, it's gonna happen. There isn't a perfect solution, so let's take a look at our options.

29.07.2025 09:02 β€” πŸ‘ 2    πŸ” 1    πŸ’¬ 0    πŸ“Œ 0
Preview
Placeholders and Pluralization Onward! Let's find a complex translation scenario. On the article page, scroll down and find the comments section

Let's look at a more complex translation, one with dynamic values and pluralization, because "1 dinosaurs" doesn't sound quite right πŸ¦–

28.07.2025 09:01 β€” πŸ‘ 1    πŸ” 1    πŸ’¬ 0    πŸ“Œ 0
Preview
Translation "Keys" We're *almost* ready to start translating this site! But before we get started, I want to show a little teensy tiny problem with our setup so far. We still have this "Hello World!" text so jump into "templates/article/index

One last thing before we finally translate the site: translation "keys". Let's look at why we use these, how to use them, and how YAML helps!

25.07.2025 09:01 β€” πŸ‘ 1    πŸ” 1    πŸ’¬ 0    πŸ“Œ 0
Preview
Translating Content It's time to actually do some translating! There's two main places you typically translate content. First: in PHP code, like flash messages in your controllers

Let's do the real work of translating! See where and how you translate text, the "anatomy" of a translation, creating, and loading them.

24.07.2025 09:01 β€” πŸ‘ 1    πŸ” 1    πŸ’¬ 0    πŸ“Œ 0
Preview
Create a Language Switcher We have localized routing up and running, but we can only switch locales by manually updating the URL. That won't do! Instead, let's add a language switcher! Up here, next to our search form, we need...

Let's create a nifty language switcher widget since having users manually manipulate the URL in their address bar is a huge bummer.

23.07.2025 09:01 β€” πŸ‘ 2    πŸ” 1    πŸ’¬ 0    πŸ“Œ 0
Preview
Cascade Persist Check out this error: it's a doozy! > An entity was found through the relationship "Starship.droids" that was not configured to "cascade persist" operations for entity "StarshipDroid"

There’s one piece of magic needed to get addDroid() to work again: cascade persist. let’s crack open this underused but potentially dangerous option

22.07.2025 09:02 β€” πŸ‘ 1    πŸ” 0    πŸ’¬ 0    πŸ“Œ 0
Preview
Localized Routes We installed the translation component. Go us! Also, our pages are advertised via the "lang" attribute as our default locale: "en"

With the Translation component installed and configured, our next step is to figure out what language a user wants. There are a couple ways to do this, but let's look at the most robust one: Localized, or Translated routing.

22.07.2025 09:02 β€” πŸ‘ 2    πŸ” 1    πŸ’¬ 0    πŸ“Œ 0
Preview
Installing the Translation Component Hey friends! e alegro de que te hayas unido a mΓ­ en este curso de sobre las traducciones de Symfony! In this tutorial, we're celebrating one of the oldest components in Symfony, but for the first time...

πŸ‡¬πŸ‡§ πŸ”„ πŸ‡ͺπŸ‡Έ πŸ”„ πŸ‡«πŸ‡· New course all about the Symfony Translation component! We'll take an English-only site, translate it into multiple languages, add a language switcher and let it loose on the world... First let's install the component.

21.07.2025 09:02 β€” πŸ‘ 4    πŸ” 2    πŸ’¬ 0    πŸ“Œ 0
Preview
Re-adding addDroid(): Hide that Join Entity! You might be asking yourself: "Hold up, do I really need to create a "StarshipDroid" object every time I want to simply assign a droid to a starship?" I think that's too much work. Could we get back to...

life used to be *so* nice:
$starship->addDroid($droid), then we added this join entity and it all got mucked up: let’s re-add addDroid() & start getting it to work again

21.07.2025 09:02 β€” πŸ‘ 0    πŸ” 0    πŸ’¬ 0    πŸ“Œ 0
Preview
Hiding the Join Entity Refresh the homepage and... busted! In the homepage template, we're referencing "ship.droidNames"

Even though our ManyToMany is gone, what we have is still basically a many to many from ship to droids. Let’s start to β€œhide” the join entity β€œimplementation” detail

18.07.2025 09:03 β€” πŸ‘ 0    πŸ” 0    πŸ’¬ 0    πŸ“Œ 0
Preview
Persisting the More Complex Many-to-Many Relationship We refactored our many-to-many relationship to include a join entity called "StarshipDroid", instead of relying on Doctrine to create the join table for us. Reload our fixtures, but hold on to your hats:...

With the new join entity setup, persisting is a bit more work (for now), let’s find out how to do it!

17.07.2025 09:03 β€” πŸ‘ 1    πŸ” 0    πŸ’¬ 0    πŸ“Œ 0
Preview
Many-to-Many but with Extra Data ManyToMany relations are the *one* place in Doctrine where we have a table in our database - "starship_droid" - but no corresponding entity in our app. But there's a catch: we can't add extra *columns*...

Our goal: add extra fields to the ManyToMany join table, but since that’s not possible, we’ll replicate the db relation with a join entity & two ManyToOne relations

16.07.2025 09:03 β€” πŸ‘ 1    πŸ” 0    πŸ’¬ 0    πŸ“Œ 0
Preview
Joining Across a Many-to-Many Relationship Ever wondered which starship in the fleet is crawling with the most droids? Me too! Let's list every ship in ascending order based on their droid count. Dive into "src/Controller/MainController

How do we join across a ManyToMany relation with that nasty join table in the center? By ignoring it! It’s all properties & objects

15.07.2025 09:04 β€” πŸ‘ 0    πŸ” 0    πŸ’¬ 0    πŸ“Œ 0
Preview
Many To Many with Foundry Remember back in "AppFixtures" when we manually assigned a "Droid" to a "Starship"? That was fun! But now, I want to create an *army* of "droids", a fleet of "starships" and assign them all at once. Get...

Can we create 100 droids and randomly assign 1-5 of them to each of the 100 starships in the fixtures? With Foundry it’s a simple one liner!

11.07.2025 09:04 β€” πŸ‘ 1    πŸ” 0    πŸ’¬ 0    πŸ“Œ 0
Preview
Accessing Data on a ManyToMany Simple goal really: print all the droids assigned to a "Starship". If you got comfortable with the "OneToMany" relation from "Starship" to its parts, then you're going to love this! Open the template...

Let’s get into rendering a ManyToMany: because Starship holds a collection of Droid objects, it’s delightfully simple + we’ll add a β€œsmart” method to Starship

10.07.2025 09:03 β€” πŸ‘ 3    πŸ” 0    πŸ’¬ 0    πŸ“Œ 0
Preview
Setting Many To Many Relations Alright, let's dive into the final part of "ManyToMany". In one corner, we have the "Starship" entity, which is linked via a "ManyToMany" relationship with the "Droid" entity

Don’t think: just put the objects together: $ship->addDroid($droid), then marvel as Doctrine handles inserting into and deleting from the join table

09.07.2025 09:02 β€” πŸ‘ 1    πŸ” 0    πŸ’¬ 0    πŸ“Œ 0
Preview
Many-To-Many Relationship Alrighty, we've got a "Starship" entity and a "Droid" entity set up and ready to mingle. How do we get these two entities to connect? Picture it this way: Each "Starship" is going to need a crew of "Droids"...

Each starship deserves many droids & each droid can serve on many starships. Hey! That’s a ManyToMany relation! Once again, Doctrine let’s us think about *objects* instead of db details. But what it does behind the scenes on the db is crazy-cool!

08.07.2025 09:02 β€” πŸ‘ 0    πŸ” 0    πŸ’¬ 0    πŸ“Œ 0
Preview
Droid Entity for the ManyToMany Relationship We've had a good taste of relationship types by now. We've seen "ManyToOne" and "OneToMany", which are really the *same* relationship type, viewed from different sides

Our starships need droids, ya know for maintenance instead of these unreliable humans (and for comic relief) πŸ€–

03.07.2025 09:02 β€” πŸ‘ 0    πŸ” 0    πŸ’¬ 0    πŸ“Œ 0
Preview
Adding a Search + the Request Object Time for a quick, but useful, detour away from Doctrine Relations. I know Doctrine relations rock, but so will this! I want to add a search bar to our page

Time for a quick break from relations to add a search: the Request object & how *not* to do an OR where

02.07.2025 09:02 β€” πŸ‘ 1    πŸ” 0    πŸ’¬ 0    πŸ“Œ 0
Preview
Joining to Avoid the N+1 Trap We've got a "parts" table, and we're using it! But now we want to rank the parts by "price" descending, because if we're gonna upsell, might as well start with the most expensive ones, right? This is...

What is the N+1 query problem?
It’s not as bad as the little Bobby Drop Table problem, but it *can* be a performance bummer. Let’s fix with a join & addSelect()

01.07.2025 09:02 β€” πŸ‘ 1    πŸ” 0    πŸ’¬ 0    πŸ“Œ 0
Preview
Listing Parts New mission: we need a page that lists *every* available part. Our Ferengi sales team will use this for some classic upselling

Let’s list some starship parts! We’ll use our relationship from the *other” side & see Twig’s neat cycle() function

30.06.2025 09:02 β€” πŸ‘ 0    πŸ” 0    πŸ’¬ 0    πŸ“Œ 0
Preview
The Clever Criteria System We've got this super handy "$ship->getParts()" method: it returns all the parts for our starship. But the fiscal year is coming to a close, and we need to plan our budget

A hidden treasure in Doctrine is the Criteria object which lets us modify the query on a relation, e.g. so $ship->getParts() only returns parts over a certain price. Magic!

27.06.2025 09:02 β€” πŸ‘ 1    πŸ” 0    πŸ’¬ 0    πŸ“Œ 0
Preview
Ordering a Relation and "fetch" type Click into an "in progress" starship. Then open: "templates/starship/show

$ship->getParts() is cool. But what if we want to order those parts? Are we out of luck? Nope! Thanks to #[ORM\OrderBy()] symfonycasts.com/screencast/d...

26.06.2025 09:03 β€” πŸ‘ 1    πŸ” 0    πŸ’¬ 0    πŸ“Œ 0
Preview
Orphan Removal When we used "make:entity" to add a relation, it asked us about "orphanRemoval". Time to find out what that is & when to use it

make:entity asks us if we want "orphan removal" for most relationships. Is that as sinister as it sounds? Nope! But let’s find out when it’s useful. symfonycasts.com/screencast/d...

25.06.2025 09:02 β€” πŸ‘ 1    πŸ” 0    πŸ’¬ 0    πŸ“Œ 0
Preview
The Two Sides of a Relation: Owning vs Inverse Fun fact for your upcoming Doctrine taco party: Every relationship can be viewed from two different sides. Take "Starship": it has multiple parts, making it a one-to-many relationship from the…

There’s a subtle detail in every Doctrine relation: the owning vs side. We’ll chat about what this means and how our *own* code prevents it from being an issue. symfonycasts.com/screencast/d...

24.06.2025 14:50 β€” πŸ‘ 1    πŸ” 0    πŸ’¬ 0    πŸ“Œ 0

@symfonycasts.com is following 5 prominent accounts