I recently encountered a blocking issue in my Symfony Project. I just upgraded from 3.4 to 4.4. I followed the guidelines and replaced all deprecated notices.
I have a huge and dirty controller for a side feature.
As written in SF doc I replaced :
class XXXController extends Controller
by
class XXXController extends AbstractController
In my logic the function getParameter() from src/Symfony/Bundle/FrameworkBundle/Controller/AbstractController.php is called.
protected function getParameter(string $name)
{
if (!$this->container->has('parameter_bag')) {
throw new ServiceNotFoundException('parameter_bag.', null, null, [], sprintf('The "%s::getParameter()" method is missing a parameter bag to work properly. Did you forget to register your controller as a service subscriber? This can be fixed either by using autoconfiguration or by manually wiring a "parameter_bag" in the service locator passed to the controller.', static::class));
}
return $this->container->get('parameter_bag')->get($name);
}
But I always fall in the 'if' condition.
Auto-wiring declaration in my service.yml like :
services:
_defaults:
autowire: true # Automatically injects dependencies in your services.
autoconfigure: true # Automatically registers your services as commands, event subscribers, etc.
To overwrite the getParameters() in my controller.
To declare my controller has a service but it began to get really messy because the targeted method is more than 1k lines long.
I tried to bind it as a common argument in service.yml
Now my only solution is to keep extending the old Symfony\Bundle\FrameworkBundle\Controller for every controller where I need to call getParameter() on the container.
Is there an easy way for injecting Symfony\Component\DependencyInjection\ParameterBag\ParameterBag in my targeted controller ? Am I missing something obvious ?
I got :
Information for Service "parameter_bag"
=======================================
There is an issue with the notice about the service been removed from container ? I can't find why tho.
{-code-6}
I got :
{-code-7}
I declared it in my service.yml
{-code-8}
__construct() method in XXXController
{-code-9}
But using this solution I always get the error :
{-code-10}
Am I stuck in a loop ? Defining in the constructor method and service.yml is not enought ? How can I provide the ParameterBag ?
NB :
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Find the answer in similar questions on our website.
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.
PHP (from the English Hypertext Preprocessor - hypertext preprocessor) is a scripting programming language for developing web applications. Supported by most hosting providers, it is one of the most popular tools for creating dynamic websites.
The PHP scripting language has gained wide popularity due to its processing speed, simplicity, cross-platform, functionality and distribution of source codes under its own license.
https://www.php.net/
Symfony compares favorably with other PHP frameworks in terms of reliability and maturity. This framework appeared a long time ago, in 2005, that is, it has existed much longer than most of the other tools we are considering. It is popular for its web standards compliance and PHP design patterns.
https://symfony.com/
Welcome to the Q&A site for web developers. Here you can ask a question about the problem you are facing and get answers from other experts. We have created a user-friendly interface so that you can quickly and free of charge ask a question about a web programming problem. We also invite other experts to join our community and help other members who ask questions. In addition, you can use our search for questions with a solution.
Ask about the real problem you are facing. Describe in detail what you are doing and what you want to achieve.
Our goal is to create a strong community in which everyone will support each other. If you find a question and know the answer to it, help others with your knowledge.