When rendering Symfony twig templates sometimes you might need to show one html element and hide another element depending if you have flash error/notice messages or not. For example if you have a page with registration form you might want to hide the form if it was submitted successfully and you only want to display a success message. For that you will need to check if the flash messages set by your controller are empty or not.
Continue reading “Symfony and Twig: how to check if flash messages are not empty”Author: kikminev
PHP spread operator
The so called spread operator was introduced in PHP 7.4 and it has rather peculiar usage. Given an array of elements it will take each element and spread it to it’s own placeholder element. E.g. the array:
Continue reading “PHP spread operator”Symfony get HTTP_X_FORWARDED_PROTO in controller
It’s often the case that people that use Cloudflare use the SSL option of cloudflare that secures the connection from the client to Cloudflare, but not from Cloudflare to the actual hosting server. In this case people might get the impression that the user is accessing the site from https but actually the hosting server is accessed with http and Symfony’s $request->isSecure() returns false.
Continue reading “Symfony get HTTP_X_FORWARDED_PROTO in controller”PHP Generators and yield
PHP generators allows you to iterate through data by using less memory compared to a standard foreach function. Simple example: If you want to display the numbers between 1 and 5000000 with a simple foreach you may hit the memory limits used by PHP.
Continue reading “PHP Generators and yield”