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.

Symfony 2 : multiple and dynamic database connection

If you use ConnectionFactory, your event subscribers attached to the connection will stop working, for example stofDoctrineExtensions. Here is my method. I have as with ConnectionFactory have empty connection and EntityManager. While working I just replace connection configuration by Reflections. Works on SF 2.0.10 😉 class YourService extends ContainerAware { public function switchDatabase($dbName, $dbUser, $dbPass) … Read more

How to specify the scope of Google API to get the birthday

I just used and tested it using Try It. I tested it with all of the different scopes. https://www.googleapis.com/auth/plus.login Know your basic profile info and list of people in your circles. https://www.googleapis.com/auth/plus.me Know who you are on Google https://www.googleapis.com/auth/userinfo.email View your email address https://www.googleapis.com/auth/userinfo.profile View basic information about your account It doesn’t appear to matter … Read more

passing data from controller to Type symfony2

You can pass parameters to the form class as follows: //PlumeOptionsType.php protected $profile; public function __construct (Profile $profile) { $this->profile = $profile; } Then use it in the query_builder of your buildForm: $profile = $this->profile; $builder->add(‘framePlume’, ‘entity’, array( ‘class’ => ‘DessinPlumeBundle:PhysicalPlume’, ‘query_builder’ => function(EntityRepository $er) use ($profile) { return $er->createQueryBuilder(‘pp’) ->where(“pp.profile = :profile”) ->orderBy(‘pp.index’, ‘ASC’) … Read more

Symfony2: how to log user out manually in controller?

Logout in Symfony2 is handled by so called logout handler which is just a lister that is executed when URL match pattern from security configuration, ie. if URL is let’s say /logout then this listener is executed. There are two build-in logout handlers: CookieClearingLogoutHandler which simply clears all cookies. SessionLogoutHandler which invalidates the session All … Read more

How can I access a service outside of a controller with Symfony2?

The Symfony distribution relies heavily on dependency injection. This means that usually, dependencies are injected directly into your object via the constructor, the setters or via other means (like reflection over properties). Your API wrapper service is then a dependency for other objects of your application. That being said, it would be rather difficult to … Read more

symfony2: how to use group_concat in QueryBuilder

If you want to use it in QueryBuilder you must : 1) add DQL functions GroupConcat: GroupConcat 2 ) Registering GroupConcat :DQL User Defined Functions another alternative is to use NativeQuery :Native SQL In symfony2 registering a function DQL it’s very simple just add GROUP_CONCAT in config.yml like: entity_managers: default: dql: string_functions: GROUP_CONCAT: YourBundle\Query\Mysql\GroupConcat For … Read more

Why composer install timeouts after 300 seconds?

try composer update/install -o -vvv and check wether the package is being loaded from composer’s cache. if yes try clearing composer’s cache or try adding -cache-dir=/dev/null. To force downloading an archive instead of cloning sources, use the –prefer-dist option in combination with –no-dev. Otherwise you could try raising composer’s process timeout value: export COMPOSER_PROCESS_TIMEOUT=600 ( … Read more