How To Override FOSUserBundle

Before learning how to override FOS, one should know what exactly FOS is and how it works! FOS is short for Friends Of Symfony. So now, before using FOSUserBundle, you should probably find more about what Symfony2 exactly is.

Symfony2

Symfony2 is a flexible Framework for the development of PHP web application. Symfony2 can be used to build dynamic websites, web apps, web services and resources.
in-the-future-we-all-use-symfony2-1-728

Why Are We Using Symfony2?

Webmuch has always picked Symfony2 as the framework of choice for large scale PHP projects.

Well, it’s an advanced full stack PHP framework, which means it’s a complete solution for just about any kind of application. The other reason for using Symfony2 is that it uses CMF(content management framework) which makes it easier for developers to add CMF functionality to applications built with the Symfony2 PHP framework.

Webmuch team fashions outstanding applications and business workflow with the help of Symfony2 web application framework.

Advantages Of Using Symfony2

advantages

  • Symfony2 is very fast and comparable to other web frameworks.
  • It reduces the number of resources needed.
  • Symfony2 encourages to write framework independent, and it’s built commercial enterprise web application.
  • It allows a lot of flexibility around how the project is setup.
  • Symfony2  is an Open source technology.

What Is FOSUserBundle?

5779484d04a8e47017db438ee3378a52

FOSUserBundle provides a default functionality for a user for registration or login on to a website. One just needs to download FOSUserBundle and install the application. It provides a login panel for the user to register on the website. It contains some fields:

  • E-Mail
  • User name
  • Password
  • Verification

And here are some simple steps for overriding FOSUserBundle.

Installation Steps

symfony_fosuser Installation

Installation is a quick (For Real!)

  1. Download FOSUserBundle using composer
  2. Enable the Bundle
  3. Create your User class
  4. Configure your application’s security.yml
  5. Configure the FOSUserBundle
  6. Import FOSUserBundle routing
  7. Update your database schema

 

What These Steps Do 

In FOSUserBundle, the fields like username and email idare not null by default. Admin or some Power Users may want to create a new vendor whose

In FOSUserBundle the fields like username and email id are not null by default. Admins or some Power Users may want to create a new vendor whose username and email id may not be known to the Admin or the Power User. So there is a requirement that username and email should remain null.

For this purpose, a new base user is created which may override the default components of the FOS User. This new base user is created in FOS/UserBundle/Model/User.php as follows:

 

 

From the above code, it can be seen that all the fields are allowed to be null which is not the case in FOSUserBundle.

After creating this NewBaseUser, it is used in the file ‘user.php’ of the UserBundle. Instead of using the FOSUserBundle in the ‘user.php’, the following statement should be used on the top of the file.

 

Again in the front registration page, email id and username cannot remain null. For this purpose, we have to assign validation to the username and email id for the normal user to get registered.

This is achieved as follows :

 

 

The code for overriding is as follows:

 

Wooh! That was a long one, eh? Just a bit more to go, you’re almost there.

PseudoCode For The Code Above:

Again in front registration page, email id and username cannot remain null. For this purpose, we have to assign validation to the username and email id for the normal user to get registered.

This is achieved as follows:

 

Feel free to leave comments if you appreciate the tutorial or if you have any queries. Do Subscribe to our newsletter. Keep reading, and enjoy!

Cheerio!

 

 

FOR MORE AWESOME TUTORIALS:

 

 

1. How To Embed EAV Model In Symfony2 Collection Form

newfeatimagecollection

 

 

 

 

 

 

2. How To Create A Business Application In Data Grid – ORO Platform

Oro Platform

 

 

 

 

 

 

3. How To Create A Multi Column Design Layout Using Wookmark jQuery.

wookmark jquery

 

 

 

 

 

4. Image Flip Using jQuery

imageflip