Skip to content
Advertisement

How to automatically trim string when persisting a Doctrine entity?

Let’s say I have this entity:

JavaScript

My controller:

JavaScript

I want doctrine to register the name of myEntity as awesome name and not awesome name .

Is there a way to configure doctrine to do this?

Advertisement

Answer

You do not need to “configure doctrine” in any way. Just use PHP and introduce the logic in your entity:

JavaScript

This way your data will be in a consistent state before you persist it in the database.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement