symfony
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/
Symfony2 -> Twig -> Form -> Field -> Set rendered = true
Am I missing the question here? If you want to set a field as rendered even though it is not the simple call is: {% do form.x.setRendered %} If I misunderstood, my apologies.
How do I get the entity that represents the current user in Symfony?
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 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 delete rows from join-table (ManyToMany) in Doctrine?
To set cascade on doctrine level: @ORM\ManyToMany(targetEntity=”Target”, inversedBy=”inverse”, cascade={“remove”, “persist”}) More info: Doctrine2 Annotation Reference. To set cascade on mysql level: @ORM\JoinColumn(onDelete=”CASCADE”, onUpdate=”CASCADE”)