Dragos Holban

Symfony2 Doctrine Migrations with Unique Indexes (Slugs)

This is something me and my colleagues encounter from time to time. The Problem One of the problems of adding unique indexes to existing data, like adding the sluggable Doctrine behaviour using the StofDoctrineExtensionsBundle, is that the generated migration will end up throwing an error: [crayon-5f2a0b9a96881903979198-i/] Causes Since the default values for the new MySQL column are not unique,…


How to Create a Custom Symfony2 Password Encoder

As you advance through your Symfony2 developer life, you will probably encounter the need to create a custom password encoder for you Symfony2 project. One of the most common reasons to do this, is when you migrate from an old project (different technology) and you have to keep users together with their working passwords. As you probably cannot find out the plain passwords to be able to just save…


How to Fix Symfony2 Ajax Login Redirect

You probably noticed that sometimes an Ajax request will return the login page instead of the actual content is should return. This happens when the user has beed logged out in the background and the current page does not reflect that (it could happen if the session expired or if the user simply logged out from another browser window/tab). Here's a quick way to fix this: we will create an event…


How to Enable Email Confirmation on FOSUserBundle Profile Edit

We all know and use FOSUserBundle in our Symfony applications, so much it became kind of a standard. It provides everything you need for user management: login, registration, email confirmation and much more control over the access of the user in your application. But we found a thing missing from this awesome package: email confirmation after the initial email address has been changed through a…


How to Store Latitude and Longitude in MySQL

As we know, a latitude value can be between -90 and +90 degrees, whereas a longitude value can be between -180 and +180 degrees. To get accuracy to within a meter, only six decimal places are needed, which is sufficient for most cases. But you can go even further by using eight places which will give you more than centimeter-level accuracy.


How Teams Use Git for Big Projects

Every time a new member joins our team we have to guide him through our Git workflow. So I decided to write everything here in order to simply send them the link (and help others interested in learning how a real development team uses Git).


Linux Commands Every Web Developer Should Know

Here's a list of Linux commands I found very useful throughout the years. You might want to bookmark it as you'll surely need it again someday.


How to Add Share Buttons to Symfony2 Generated Web Pages

Some projects require you to add social share buttons for their pages. I'm gonna show you a simple way to do this using the Socialitejs JavaScript library. First you're gonna have to download the Socialitejs library, save it to your bundle Resources/public/js folder and publish the assets. If you have a general layout that is inherited by all your specific page templates (like it's usually the…


Symfony2: Gedmo SoftDeletable Doctrine Entities with Unique Index Columns

There is a problem when using the SoftDeletable Doctrine extension for entities that have some unique index columns. The most obvious example is User entities. An User has at least one column that needs to be unique (username and/or email). When soft-deleting an User the actual record will stay in the db table. Now if you try to create a new one with the same username/email, the validation will…