Auto iconv of Doctrine query
How do I 开发者_JAVA百科set up Doctrine to automatically run iconv() when building a query and fetching data?
Why don't you just tell the RDBMS you're using to send the data in UTF-8? Doctrine_Connection
has a setCharset
method for this:
$connection->setCharset('utf8');
Well, I hope nobody ever has to face charset conversion problems in their lives and all charsets except UTF8 will soon be a thing of the past. Anyway, just to give some feedback to my own question. I solved by writing a custom hydrator that extends Record hydrator and by overriding some symfony prcessValues methods of Filter base classes like this:
abstract class BaseFormFilterDoctrine extends sfFormFilterDoctrine
{
public function setup()
{
}
public function processValues($values)
{
$values = parent::processValues($values);
$charset = strtolower(str_replace('-','',$this->getTable()->getConnection()->getCharset()));
if ($charset != 'utf8')
{
foreach ($values as $key => $value)
{
if (isset($value['text']))
{
$values[$key]['text'] = iconv('utf8', $charset, $value['text']);
}
}
}
return $values;
}
}
setCollation()
is the corresponding one.
精彩评论