FOSUserBundle redirect from login page after logged in

The easier solution is to add these two lines to your app/config/security.yml: always_use_default_target_path & default_target_path, e.g.: firewalls: main: pattern: ^/ form_login: provider: fos_userbundle csrf_provider: form.csrf_provider login_path: /login check_path: /login_check always_use_default_target_path: false default_target_path: /your/start/path/

How to get the logged-in user’s ID in Symfony

Current Symfony versions (Symfony 4, Symfony >=3.2) Since Symfony >=3.2 you can simply expect a UserInterface implementation to be injected to your controller action directly. You can then call getId() to retrieve user’s identifier: class DefaultController extends Controller { // when the user is mandatory (e.g. behind a firewall) public function fooAction(UserInterface $user) { $userId … Read more

How to set the exit status code in a Symfony2 command?

In the base Command class: if ($this->code) { $statusCode = call_user_func($this->code, $input, $output); } else { $statusCode = $this->execute($input, $output); } return is_numeric($statusCode) ? (int) $statusCode : 0; So simply return the exit code from your execute() function. Your console command will exit with this code as long as it is a numeric value.

Access parameter from the Command Class

Simple way, let command extend ContainerAwareCommand $this->getContainer()->getParameter(‘parameter_name’); or You should create seperate service class $service = $this->getContainer()->get(‘less_css_compiler’); //services.yml services: less_css_compiler: class: MyVendor\MyBundle\Service\LessCompiler arguments: [%less_compiler%] In service class, create constructor like above you mentioned public function __construct($less_compiler) { $this->less_compiler = $less_compiler; } Call the service from command class. Thats it. Reason: You are making command class … Read more

Apply class to Symfony2 Form Label

I’ve got it… <?php echo $view[‘form’]->label($form[‘first_name’], ‘First Name’, array( ‘label_attr’ => array(‘class’ => ‘control-label’), )) ?> Apparently “attr” is “label_attr” for labels fields. P.S. Corresponding twig code {{ form_label(form.first_name, ‘First Name’, { ‘label_attr’: {‘class’: ‘control-label’} }) }}

Persisting other entities inside preUpdate of Doctrine Entity Listener

I give all the credits to Richard for pointing me into the right direction, so I’m accepting his answer. Nevertheless I also publish my answer with the complete code for future visitors. class ProjectEntitySubscriber implements EventSubscriber { public function getSubscribedEvents() { return array( ‘onFlush’, ); } public function onFlush(OnFlushEventArgs $args) { $em = $args->getEntityManager(); $uow … Read more