|
View:
New views
3 Messages
—
Rating Filter:
Alert me
|
|
|
Zend Framework and UTF-8Hi
I've seen that all data from Zend_Locale_Data (the XML files) are coded in UTF-8, it's a wise decision, however i'm planning to deploy an application using UTF-8 and i don't know if all the Zend Framework libs are ready to handle this. Are there any suggestion to work with UTF-8? i'm playing around with "mbstring" library, but i want to know if there is a (nearly) standard way to code UTF-8 applications. Maybe in PHP6 this will be more easy to do, but at the moment.... Thanks -- Xavier Vidal Piera Enginyer Tècnic Informàtic de Gestió Tècnic Especialista Informàtic d'equips xavividal@... xvidal@... http://web.xaviervidal.net 610.68.41.78 |
|
|
Re: Zend Framework and UTF-8All I18N aware components are working with UTF-8.
I can't say for other components where output is generated. Generally the components which are not generating output are no problem at all (f.e. Session, Cache and so on...). Several people around here have already created sites which are UTF-8 coded and as it is a standard today it should be really no problem at all. I would be surprised if any component from ZF does not support UTF-8. And UTF-8 has nothing to do with PHP6 as long as you have no need to name your methods or variables with UTF-8 characters :-) Greetings Thomas Weidner, I18N Team Leader http://www.thomasweidner.com ----- Original Message ----- From: "Xavier Vidal Piera" <xavividal@...> To: <fw-i18n@...> Sent: Monday, February 18, 2008 5:18 PM Subject: [fw-i18n] Zend Framework and UTF-8 > Hi > > I've seen that all data from Zend_Locale_Data (the XML files) are coded in > UTF-8, it's a wise decision, however i'm planning to deploy an application > using UTF-8 and i don't know if all the Zend Framework libs are ready to > handle this. > > Are there any suggestion to work with UTF-8? i'm playing around with > "mbstring" library, but i want to know if there is a (nearly) standard way > to code UTF-8 applications. > > Maybe in PHP6 this will be more easy to do, but at the moment.... > > Thanks > > -- > Xavier Vidal Piera > Enginyer Tècnic Informàtic de Gestió > Tècnic Especialista Informàtic d'equips > xavividal@... > xvidal@... > http://web.xaviervidal.net > 610.68.41.78 > |
|
|
Re: Zend Framework and UTF-8I haven't noted any major UTF-8 problems. There are a few caveats of course. Be careful around filtering logic which may in older versions (perhaps even still in current ones) has difficulty in determining alphabetic and string character count detection for some multibyte strings. Also ensure Zend_View is setup to use UTF-8 encoding. Finally also set Zend_Controller_Request_Http to send UTF-8 headers for Content-Type. If you get these right the rest is straightforward enough. I still find most web applications however get one or more of these wrong - which cause messy problems when your name contains a UTF-8 character like mine ;). I still can't some sites to display my real name...
Here's an edited Bootstrap file showing how some of the above steps can be organised: <?php require_once 'Zend/Loader.php'; class Bootstrap { public static $root = ''; public static $frontController = null; public static $registry = null; public static function run() { self::prepare(); $response = self::$frontController->dispatch(); self::sendResponse($response); } public static function setupEnvironment() { error_reporting(E_ALL|E_STRICT); ini_set('display_errors', true); // switch in production! date_default_timezone_set('Europe/London'); self::$root = dirname(dirname(__FILE__)); } public static function prepare() { self::setupEnvironment(); Zend_Loader::registerAutoload(); self::setupRegistry(); self::setupConfiguration(); self::setupFrontController(); self::setupView(); self::setupDatabase(); } public static function setupFrontController() { self::$frontController = Zend_Controller_Front::getInstance(); self::$frontController->throwExceptions(); self::$frontController->returnResponse(true); self::$frontController->setControllerDirectory( self::$root . '/application/controllers' ); self::$frontController->setParam('registry', self::$registry); } public static function setupRegistry() { self::$registry = new Zend_Registry(array(), ArrayObject::ARRAY_AS_PROPS); Zend_Registry::setInstance(self::$registry); } public static function setupConfiguration() { $config = new Zend_Config_Ini( self::$root . '/config/config.ini', 'general' ); self::$registry->configuration = $config; } public static function setupDatabase() { $config = self::$registry->configuration; $db = Zend_Db::factory($config->db->adapter, $config->db->toArray()); $db->query("SET NAMES 'utf8'"); self::$registry->database = $db; Zend_Db_Table::setDefaultAdapter($db); } public static function setupView() { $view = new Zend_View; $view->setEncoding('UTF-8'); $viewRenderer = new Zend_Controller_Action_Helper_ViewRenderer($view); Zend_Controller_Action_HelperBroker::addHelper($viewRenderer); Zend_Layout::startMvc( array('layoutPath' => self::$root . '/application/views/layouts') ); } public static function sendResponse(Zend_Controller_Response_Http $response) { $response->setHeader('Content-Type', 'text/html; charset=UTF-8', true); $response->sendResponse(); } }
Pádraic Brady
http://blog.astrumfutura.com http://www.patternsforphp.com OpenID Europe Foundation - Irish Representative |
| Free Forum Powered by Nabble | Forum Help |