Dec 29, 2008

Unicode and preg_replace()

When you're dealing with PHP and finally start using unicode instead of whatever non-unicode encodings, you might find a some of your symbols being transformed into rubbish, especially when dealing with non-latin alphabet.

The answer is to use a “u” flag in the expression string:

$s = preg_replace('/\s/u', $s);

Dec 16, 2008

sfGuardPlugin: Database Prefix

With symfony, it's kinda funny to search for documentation, since it's widely distributed across wiki, book, and various external sources, like Propel website.

That is why when you need something small and easy, but you don't know how to do this, it's usually faster to try that yourself first, search for an answer later. This is actually not the way I prefer to do stuff, so I will share some experiences about how to do small stuff in symfony.

So, the problem is, I have a single database on my web hosting available. However, I came across a situation where I needed two separate sets of sfGuardUser-s. To achieve this, I had to go the usual way — add a prefix to the tables.

All I had to do was to add “prfx_” to all the tables mentioned in <project-name>/plugins/sfGuardPlugin/config/schema.yml and then rebuild stuff with propel:

symfony propel:build-all

or, if you want to keep your existing data, rename tables in database manually, and then...

symfony propel:build-sql
symfony propel:build-form
symfony propel:build-model

...and you're set.