In my twig template there are some variables that are required on each page like userName, userId or userImage. What is the best way to inject them into the template? I already read the article How to Inject Variables into all Templates but how could I write a variable (e.g. current user) into the config/packages/twig.php file? Right now there is
Tag: symfony4
Script cache:clear returned with error code 255
I installed Symfony 4.2 via composer composer create-project Symfony/website-skeleton my-project everything works correctly, then I put the project in gitlab. a friend of mine tried to clone it on …
How to use the logger in a console command on Symfony 4?
I’ve recently gone from using Symfony 2.7 to 4.2. Previously in my commands in order to log to a file I used something like: This functionality appears to have changed. I can log from a controller following https://symfony.com/doc/current/logging.html I can output to the console using: But as much as I stare at the information on the symfony website I just
How to get query string in Symfony 4
I am trying to access the query string parameters in Symfony 4 namespace AppController; use SymfonyComponentHttpFoundationRequestStack; class Home extends Controller { private $request; …
Symfony 4 – controllers in two directories
In my application, I use Symfony 4. I want Symfony to search for controllers in two directories: A and B. I found something like this: controllers: resource: ‘../src/DirectoryA/Controller/’ …
Symfony 4 : Override public services in container
I am migrating our project to Symfony 4. In my test suites, we used PHPUnit for functional tests (I mean, we call endpoints and we check result). Often, we mock services to check different steps. Since I migrated to Symfony 4, I am facing this issue: SymfonyComponentDependencyInjectionExceptionInvalidArgumentException: The “my.service” service is already initialized, you cannot replace it. when we redefine
Validate against several constraints with OR logic in Symfony
I have a field in a request which can either be email or phone. Now I need to validate it against two constraints – the standard email constraint and a custom phone. I know that I can pass an array of constrains link this: But Validator applies the AND logic to the array of constraints, I need OR so that
Symfony 4 make:entity {entity} generate in a custom directory in a multi doctrine connection
New to symfony here I have a two connection setup in my config/packages/doctrine.yaml. Is it possible to generate an Entity class using the cli tool php bin/console make:entity Product to generate entity in a custom directory. When I run the above command the “Product” enttity class gets generated in my src/Entity/ directory but I want it to be generated according
Annotations in Symfony 4
I try to develop with Symfony 4 so I follow the tutorial on symfony.com I’ve got an error when I try to access at : This is the error : [Syntax Error] Expected PlainValue, got ”’ at position 7 in method AppControllerHomeController::home() in /Users//Documents/ProjetSymfo4/my-project/config/routes/../../src/Controller/ (which is being imported from “/Users//Documents/ProjetSymfo4/my-project/config/routes/annotations.yaml”). Make sure annotations are installed and enabled. I already ran
Creating a Symfony 4 Form without Database
I’m new to symfony and want to to create a simple contact form, take the submitted values and send them as an Email. I don’t want to save anything in the database. I followed the documentation on this page: https://symfony.com/doc/current/form/without_class.html I created a new page/action with the code from the page above: But this gives me an error: What am