So the package used in this video seems to now be archived sensio/framework-extra-bundle and I beleive this was because these featured were bundled into the symfony 6.2 release? (correct me if I am wrong)

In this course we are using 6.1 and don't have the option todo this as part of Symfony by default (I don't think) and we don't have the option of installing the package mentioned anymore.

I guess we would typically just need to upgrade to Symfony 6.2 here instead and not install any packages to make this work?

| Reply |

Hey @bagwaa!

Yeah, upgrading to at least 6.2 (although 6.4 is the only 6.x that's still supported) should be easy enough. Here's a nice guide for switching from sensio/framework-extra-bundle to native Symfony attributes.

Our Doctrine & Symfony 7 course is coming out soon and it will use the native attributes!

1 | Reply |

Nice! thanks for the reply :)

| Reply |
developer avatar developer 2 years ago

Hello,

how do I add a 404 error message using paramConverter ?

| Reply |

Hey @developer

I believe you cannot easily change the paramConverter error message, but that message is only seen when the app is in the dev environment. To customize what the end-user will actually see, please check this docs https://symfony.com/doc/current/controller/error_pages.html#example-404-error-template

Cheers!

| Reply |
Default user avatar unknown 2 years ago edited
Comment was deleted.
t5810 avatar t5810 2 years ago edited

Hi

I had downloaded the code from this course (folder start), and I am trying to code along. When I attempt to run the command "composer require sensio/framework-extra-bundle ", I get the following error:

In App_KernelDevDebugContainer.php line 772:
!!
!! Attempted to call an undefined method named "registerLoader" of class "Doctrine\Common\Annotations\AnnotationRegistry".

To continue coding while I get answer to this question, i did the following:

  1. I run the command: "composer remove sensio/framework-extra-bundle"
  2. revert the function show as it was.

Any advice how to proceed?

Thanks!

| Reply |

Hey @t5810!

Ah, sorry for the trouble and the my glacially slow reply! Ok, so I see the issue - there was a bug between older version of Symfony and doctrine/annotations v2 (which is required by the sensio/framework-extra-bundle library). Anyways, the fix is to update one Symfony package:

composer up symfony/framework-bundle

That should fix the issue :). I'm running that on our course code right now so that the downloaded code works for everyone again without issues.

Cheers!

5 | Reply |

Hello, I had the same problem and when I ran composer up symfony/framework-bundle I have this new error :

Attempted to load class "Locale" from the global namespace.
Did you forget a "use" statement?

| Reply |

this is where it says the error is :

C:\Users\Fourt\Desktop\sites\mixedVinyl\vendor\symfony\translation\LocaleSwitcher.php:37

 `        $this->defaultLocale = $locale;    }    public function setLocale(string $locale): void    {        \Locale::setDefault($this->locale = $locale);        $this->requestContext?->setParameter('_locale', $locale);        foreach ($this->localeAwareServices as $service) {            $service->setLocale($locale);        } `
| Reply |

Hey @Ted

I believe you need to install the PHP intl extension. If you're in a Linux alike environment, you can install by running these commands
sudo apt-get update -y
sudo apt-get install -y php-intl

Cheers!

| Reply |
Michael-S avatar Michael-S 2 years ago

Let's say there are multiple Users that have their own Mixes, and you can only view other Users' Mixes if you have some kind of active relationship with said User, say if you are "subscribed" to them.

How would you protect against someone viewing a Mix that they're not supposed to? Would you still use the ParamConverter and check that the logged in User is subscribed to the User that owns the Mix that is passed in, or would you not use the ParamConverter and instead query based on the combo of the Mix ID and logged-in User ID, going through some bridge table that keeps track of subscriptions between Users?

Then you either display the Mix if found (knowing at that point the logged-in User has access to it), or NULL would be returned from the query either if the Mix doesn't exist, or the logged-in User has no active subscription, at which point you'd 404.

Or would you approach this case some other way entirely?

Thanks ahead of time.

| Reply |

Hey Michael,

It depends, but as you see there are many good options, and mostly it's the matter of taste. Sometimes you can prefer some option more just because the solution is easier with it. So, just use that one you would like the most. If in your code, it's easier to check it from the entity that returned by the param converter - great, that's a good way I think. But if it's easier for you to write a custom query and this way looks cleaner for you - great, go for it :) No matter what way you choose, Symfony is flexible enough and allows you to throw 404 error yourself, so both ways are valid technically, depending on which one you like the most, or which one looks cleaner to you, to your specific code.

P.S. usually calling a repository method directly is more obvious, flexible, and straightforward than param converter that mostly used for a very simple fetch. But if you can write a nice code with param converter and throw a custom 404 or even 403 - I don't see any strong arguments against it ;)

Cheers!

| Reply |

Hello,

I was wondering, why on the param converter documentation and on this video, you refers to it as @ParamConverter?
Why is the need for the @, is it because the param converters are services?

Thanks for your time!

| Reply |

Hey MaxiCom,

The @ syntax in the comments is called PHP annotations, they were pretty popular before the new PHP 8 attributes that starts with # like #[Route('/mix/new')]. So, it's a special syntax that is read by the Symfony system. And yeah, almost everything in Symfony are services ;) but basically those @ParamConverter is just an alternative way of configuration :)

Cheers!

1 | Reply |