Automatic post-registration user authentication

Symfony 4.0 This process hasn’t changed from Symfony 3 to 4 but here is an example using the newly recommended AbstractController. Both the security.token_storage and the session services are registered in the parent getSubscribedServices method so you don’t have to add those in your controller. use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use YourNameSpace\UserBundle\Entity\User; class LoginController extends AbstractController{ … Read more

Doctrine 2 can’t use nullable=false in manyToOne relation?

Use the JoinColumn annotation on your ManyToOne relation: /** * @ORM\ManyToOne(targetEntity=”Package”, inversedBy=”users”) * @ORM\JoinColumn(name=”package_id”, referencedColumnName=”id”, nullable=false) */ private $package; The ManyToOne itself cannot be nullable, because it doesn’t relate to a specific column. The JoinColumn on the other hand identifies the column in the database. Thus, you can use “normal” attributes like nullable or unique!

How to get the root dir of the Symfony2 application?

UPDATE 2018-10-21: As of this week, getRootDir() was deprecated. Please use getProjectDir() instead, as suggested in the comment section by Muzaraf Ali. —- Use this: $this->get(‘kernel’)->getRootDir(); And if you want the web root: $this->get(‘kernel’)->getRootDir() . ‘/../web’ . $this->getRequest()->getBasePath(); this will work from controller action method… EDIT: As for the services, I think the way you … Read more

How to sort findAll Doctrine’s method?

As @Lighthart as shown, yes it’s possible, although it adds significant fat to the controller and isn’t DRY. You should really define your own query in the entity repository, it’s simple and best practice. use Doctrine\ORM\EntityRepository; class UserRepository extends EntityRepository { public function findAll() { return $this->findBy(array(), array(‘username’ => ‘ASC’)); } } Then you must … Read more

Is it fine if first response is private with AppCache (Symfony2)?

I have faced same problem. I had to supply ‘public’ headers my cdn. By default when gateway caching is enabled in prod mode, it returns 200 OK with private, nocache must validate headers. I solved problem this way. In app.php, before I send response to user ($respond->send), I have overwritten the cache control header to … Read more

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