How to know which version of Symfony I have?

Run app/console –version (for Symfony3: bin/console –version), it should give you a pretty good idea. On a random project of mine, the output is: Symfony version 2.2.0-DEV – app/dev/debug If you can’t access the console, try reading symfony/src/Symfony/Component/HttpKernel/Kernel.php, where the version is hardcoded, for instance: const VERSION = ‘2.2.0’; Just in case you are wondering, … Read more

How do I get the entity that represents the current user in Symfony2?

Symfony 4+, 2019+ Approach In symfony 4 (probably 3.3 also, but only real-tested in 4) you can inject the Security service via auto-wiring in the controller like this: <?php use Symfony\Component\Security\Core\Security; class SomeClass { /** * @var Security */ private $security; public function __construct(Security $security) { $this->security = $security; } public function privatePage() : Response … Read more

How do I read from parameters.yml in a controller in symfony2?

In Symfony 2.6 and older versions, to get a parameter in a controller – you should get the container first, and then – the needed parameter. $this->container->getParameter(‘api_user’); This documentation chapter explains it. While $this->get() method in a controller will load a service (doc) In Symfony 2.7 and newer versions, to get a parameter in a … Read more

How to get config parameters in Symfony2 Twig Templates

You can use parameter substitution in the twig globals section of the config: Parameter config: parameters: app.version: 0.1.0 Twig config: twig: globals: version: ‘%app.version%’ Twig template: {{ version }} This method provides the benefit of allowing you to use the parameter in ContainerAware classes as well, using: $container->getParameter(‘app.version’);

Get current URL in Twig template?

{{ path(app.request.attributes.get(‘_route’), app.request.attributes.get(‘_route_params’)) }} If you want to read it into a view variable: {% set currentPath = path(app.request.attributes.get(‘_route’), app.request.attributes.get(‘_route_params’)) %} The app global view variable contains all sorts of useful shortcuts, such as app.session and app.security.token.user, that reference the services you might use in a controller.

Should everything really be a bundle in Symfony 2.x?

I’ve written a more thorough and updated blog post on this topic: http://elnur.pro/symfony-without-bundles/ No, not everything has to be in a bundle. You could have a structure like this: src/Vendor/Model — for models, src/Vendor/Controller — for controllers, src/Vendor/Service — for services, src/Vendor/Bundle — for bundles, like src/Vendor/Bundle/AppBundle, etc. This way, you would put in the … Read more

How to get the request parameters in Symfony 2?

The naming is not all that intuitive: use Symfony\Component\HttpFoundation\Request; public function updateAction(Request $request) { // $_GET parameters $request->query->get(‘name’); // $_POST parameters $request->request->get(‘name’); Update Nov 2021: $request->get(‘name’) has been deprecated in 5.4 and will be private as of 6.0. It’s usage has been discouraged for quite some time.

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)