![]() |
|
Snippets |
|
Since it can be annoying to have Propel ignore collation of tables in MySQL >= 4.1, you must force Propel to use UTF-8 collation by running the SET NAMES UTF8 SQL query.
In order to do that, you specify a filter that executes at every request. Specify the following code in filters.yml:
myUtf8ConnectionFilter: class: myUtf8ConnectionFilter activate: on
Create a new file called myUtf8ConnectionFilter.class.php in your application's lib folder and insert the following code:
<?php class myUtf8ConnectionFilter extends sfFilter { public function execute($filterChain) { $con = Propel::getConnection(); if ($con){ $con->executeQuery("set names utf8"); } else { throw new Exception($e); } $filterChain->execute(); } } ?>
The code was copied from this website - I am not asserting any authorship.
How to use sfMail to encode Body of Japanese Email.
The Japanese Email usually use ISO-2022-JP. But, I want to use UTF-8 of any Email template files. For example...
I create PROJECT_DIR/lib/myMail.class.php
myMail.class.php
<?php class myMail extends sfMail { public function setBody ($body) { parent::setBody(mb_convert_encoding($body, "JIS", "UTF-8")); } } ?>
OK, Use this class from your Action.
actions.class.php
public function executeSendmail() { $mail = new myMail(); .... }
Scriptaculous sends the request parameters always in UTF-8 encoding, regardless of what the page encoding has been set to. This can cause problems with special characters like german umlauts if your general characterset is not set to utf8.
The filter below acts on ajax requests only, converting the parameter values to single-byte ISO-8859-1.
You can enable this filter in your filters.yml by adding the following:
xmlhttpUtf8DecodeFilter:
class: xmlhttpUtf8DecodeFilter
Below is the code of the actual filter. Store this in the lib directory of your project/application (and do not forget to clean your cache: symfony cc).
<?php /** * This filter acts on AJAX requests and decodes the * request parameter values using the php utf8_decode() * function. * * @author jmunz <jochen.munz@virn.de> */ class xmlhttpUtf8DecodeFilter extends sfFilter { /** * Run the filter */ public function execute ($filterChain) { $request = $this->getContext()->getRequest(); // Only act if this is an ajax request if ( $request->isXmlHttpRequest() && $this->isFirstCall() ){ $params = $request->getParameterHolder()->getAll(); $this->decodeParameters($params); } // execute next filter $filterChain->execute(); } /** * Decode parameters */ private function decodeParameters(&$params){ foreach (array_keys($params) as $key) { if ( is_array($params[$key]) ) { $this->decodeParameters($params[$key]); } else { $params[$key] = utf8_decode($params[$key]); } } } }