Symfony

jQuery, Webpack and Symfony | Call jQuery in your twig files

Uncaught ReferenceError: jQuery is not defined If you encountered this error message in your console of a Symfony project using Webpack, it is very likely that you are using jQuery in the following way in your project :  Your case In the app.js file you probably called jQuery like this : And then you wanted to call in your twig jQuery file this way …

jQuery, Webpack and Symfony | Call jQuery in your twig files Lire la suite »

Symfony, Doctrine | Retrieve old data of FormType

Method for recovering old data from a FormType under Symfony You need to recover old data from an Entity in Symfony to do some processing such as managing a history or other? I will present you a method that uses Unit Of Work to compare old data of data sent via the form created by FormType. Use Unit Of Work from Doctrine To retrieve old data it is …

Symfony, Doctrine | Retrieve old data of FormType Lire la suite »

Doctrine, Symfony | Difference between two dates in MySQL (Day, month, year…)

How do I know the difference between two dates in MySQL and Doctrine? You have to use the TimeStampDiff method which takes 3 parameters (the unit, the first date, the second date) and returns a number corresponding to the difference in unit between the dates. For example:  See more details on this link which explains in detail the SQL function TIMESTAMPDIFF How to …

Doctrine, Symfony | Difference between two dates in MySQL (Day, month, year…) Lire la suite »

Symfony FormType Choice | Set data default to group of radio button

How to set a default value to a ChoiceType radio button group under Symfony 4+? Currently you probably use the forms this way: This gives you as a result a group of 3 radio buttons with only one possible choice, but if you put directly here a default value, it will overwrite the values of the entity if you want to change it afterwards. …

Symfony FormType Choice | Set data default to group of radio button Lire la suite »

Symfony, Excel, CSV | Generating a CSV file for Excel with Symfony

It’s a common practice on web applications to extract data via CSV, whether it’s to retrieve statistics or to make data backups, I’ll show you how this is easily done with Symfony via a Controller. How to generate the CSV file with a Symfony Controller To generate the file, it must be constructed as in the following example, by defining the columns of the CSV file with …

Symfony, Excel, CSV | Generating a CSV file for Excel with Symfony Lire la suite »

Symfony Event Subscriber | Restricting an ip range with an Event Subscriber

Adding an Event Subscriber under Symfony with IP range restriction As part of the tutorial, we will set up an IP range restriction to allow certain IPs, but you can use Event subscriberin any case. An Event subscriber allows us to execute code before entering in our route to a controller for example, it allows us to check certainthings like token connection, …

Symfony Event Subscriber | Restricting an ip range with an Event Subscriber Lire la suite »

Symfony 5 | Return an image via a controller route

Installation of the road First of all you need a controller with a route ready to receive an image name, and then return the image. Then you need to install the following package: compose require symfony/mime which will allow Symfony to automatically detect the mime type to return. You also need to import these packages on top of the controller. My file tree My image …

Symfony 5 | Return an image via a controller route Lire la suite »

Symfony 5 | Receive server errors by email with monolog, swiftmailer and maildev

Prerequisites of the tutorial : Install monolog: https://packagist.org/packages/symfony/monolog-bundle (Allows to receive server errors by mail) Install maildev : https://github.com/maildev/maildev (Allows to create a local SMTP server) Install swiftmailer : https://packagist.org/packages/symfony/swiftmailer-bundle (Allows to send mails under Symfony) Configure Monolog : Go to the file monolog.yaml in the folder config/packages/dev (or prod for the prod..) And define the options as in the box below to receive critical errors (so 5XX) but it …

Symfony 5 | Receive server errors by email with monolog, swiftmailer and maildev Lire la suite »

Symfony 5 | Send mail with SwiftMailer and Maildev

Prerequisite: Install SwiftMailer: https://symfony.com/doc/5.2/email.htmlInstall Maildev : Configure SwiftMailer : In the file swiftmailer.yaml which is in the config/packages folder we have access to the SMTP url which is in the .env. In the .env change the MAILER_URL. Which will send all mails on port 1025 which is the maildev reception port. Start Maildev : Go to a command prompt and type maildev, the following message will appear …

Symfony 5 | Send mail with SwiftMailer and Maildev Lire la suite »

jQuery, Webpack et Symfony | Appeler jQuery dans vos fichiers twig

Uncaught ReferenceError: jQuery is not defined Si vous avez rencontré ce message d’erreur dans votre console d’un projet Symfony utilisant Webpack, il est fort probable que vous utilisez jQuery de la manière suivante dans votre projet :  Votre cas Dans le fichier app.js vous avez surement appelé jQuery de cette manière : Et vous avez ensuite voulu appelé dans votre fichier twig jQuery de …

jQuery, Webpack et Symfony | Appeler jQuery dans vos fichiers twig Lire la suite »