Book Image

Symfony2 Essentials

Book Image

Symfony2 Essentials

Overview of this book

Table of Contents (17 chapters)
Symfony2 Essentials
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

User registration


Now we can quickly add a way to register users. This is already built in FOS; we just need to use it. To do so, we need to (as with login) enable routing, add a template, and link to the registration form. Add the following rule to routing:

fos_user_registration:
  resource: "@FOSUserBundle/Resources/config/routing/registration.xml"
  prefix: /register

Update the security file with a new access control entry at the start as follows:

access_control:
    - { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY }

This modification will add the required routings. Now we need to override the template for registration. To do this, add two files. One file is app/Resources/FOSUserBundle/views/Registration/register.html.twig with the following content:

{% extends "::base.html.twig" %}

{% trans_default_domain 'FOSUserBundle' %}

{% block body %}
<div class="ui one column stackable page grid" style="margin-top: 150px;">
    <div class="column twelve wide">
        <form...