Tag: symfony
-
How to quickly create a Symfony 5+ controller
A Symfony 5 controller is just a class. You could just use your IDE to create a new class for you, but you would need to add some boiler plate code like the namespace and then extend AbstractController and add some use statements etc. Symfony 5+ has a better way though. With just one command…
-
Working with your apps local image assets in Symfony 5+
This article is mostly about managing your apps personal images and SVG files that it uses in your User Interface. It also explains how the Assets system works to the best of my abilities and discoveries. This is the best info about assets, I have found in the docs about assets. It doesn’t mention some…
-
How to fix Symfony FosJsRoutingBundle outputs routes in browser
Yeah I got this problem once too. The routing bundle outputs the routes in your browser on a plain white background, giving the user no options to navigate etc. after they register or login. So how do you fix this? Read the last step of this article I wrote How to get URL Routes in…
-
How to secure individual Symfony AJAX api routes without using API Platform
I am in the process of updating this article entirely. Please stay tuned. Creating the Symfony route is easy. Checking if the request was sent by AJAX is again easy. But what stops a mischievous hacker from hitting that endpoint and trying to get a list of used emails or something else with a script?…
-
Symfony 5.3+ how to use Sessions with RequestStack
So some changes happened in Symfony 5.3. Previously you could get to a session with either Session or SessionInterface. Some didn’t like how that worked so now it is moved to RequestStack. The docs or article are not correct here. It shows you get to the session like this. $session = $this->requestStack->getSession(); But that doesn’t…
-
Symfony 5+ how to make a form field hidden from display
This is easier than it sounds, but I am writing this in case I need to remember what the answer is. At first I wasn’t paying attention to all of the many different Symfony form types in this long list. I totally didn’t see the HiddenType in the list or I didn’t notice it. I…
-
How to change the id for a form input in Symfony 5+
If you create your forms with classes in Symfony 5+ then changing the ID of the form fields is something you are not allowed to do apparently. LOL You can add/change the class and other attributes but not the id. For some reason Symfony ONLY lets you change the id inside the template. I don’t…
-
Symfony 5+ Twig templates don’t forget to call the parent
Twig templates use inheritance and allows you to create named sections like this. <!doctype html> <html lang=”en”> <head> <meta charset=”UTF-8″> <meta name=”viewport” content=”width=device-width, initial-scale=1, shrink-to-fit=no”> <link rel=’icon’ href=”{{ asset(‘images/favicon.ico’) }}” type=’image/x-icon’ > {% block head_extra %}{% endblock %} <title>{% block title %}{{ title }}{% endblock %}</title> {% block stylesheets %} {# ‘app’ must match the…
-
Symfony 5+ how to include page specific javascript or css when using Webpack encore and SASS
In this article I will cover how to do this with Webpack in Symfony with CSS and SASS. This is slightly confusing. Symfony has it’s own Webpack configuration called encore. Read that documentation article if you need more info, more links at the bottom of the page. Webpack Config First lets checkout the file app\webpack.config.js…
-
How to make AJAX requests to Symfony 5+ controllers
I couldn’t find anything in the documentation about this and there is little on the internet about it too. There is probably a Bundle somewhere for this or some Symfony way, but I didn’t find anything. I did find this SymfonyCast about submitting a whole form. If you need to test your Controller route read…