Tag Archives: yii

Unicode UTF-8 Issue with YII and MSSQL framework

Error :
QLSTATE[HY000]: General error: 20018 Unicode data in a Unicode-only collation or ntext data cannot be sent to clients using DB-Library (such as ISQL) or ODBC version 3.7 or earlier.

Diagnosis:

The requisite encoding UTF-8 is not getting set.

Application Stack:

MS SQL

YII framework

PHP

Red Hat

Fixes at all levels of application stack:

1. MSSQL – Checked at the database level, SQL data is getting stored and retrieved without any issues.

2. YII – ini_set(‘mssql.charset’, ‘UTF-8’); in index.php

3. PHP – in /etc/php.ini,

default_charset = “UTF-8”
mssql.charset = “UTF-8”

4. Red Hat Server

In /etc/freetds.conf –

ensure in teh global settings if dedicated server else have a separate section with these setting for your application instance

[global]
host = servername
client charset = UTF-8
tds version = 8.0
text size = 20971520

References:

– http://www.yiiframework.com/wiki/16/how-to-set-up-unicode/

– Basics: http://blog.goosoftware.co.uk/2012/12/05/how-ascii-lost-and-unicode-won/

–  http://stackoverflow.com/questions/1322421/php-sql-server-how-to-set-charset-for-connection

– http://www.craig-edmonds.com/solved-php-mssql-unicode-encoding-issues/

HTML5 offline feature in MVC framework

The tricky part, not covered by HTML5 offline help sites is –

How to implement offline feature in a MVC framework like YII?

A typical MVC works like so –

Each request goes through a dispatcher, gets redirected to the appropriate controller and the requisite action.

Now the offline help sites only consider a minimalistic architecture where the manifest file and the file to be cached are in some folder structure accessible by web request and doc root.

Decoding the offline feature implementation in a MVC framework like YII yields the following –

1. Add manifest file in a public folder where static files can be kept. Ensure it works by accessing the URL from browser and it should render the manifest file contents on the browser window. Eg: any custom/assets folder outside ‘protected’ directory in YII

2. Add manifest element to the html opening tag of the page to be cache like so –

<html manifest=”http://localhost/appname/assets/offline.appcache”>

Now, in YII, HTML tag is in global layout. So if you add manifest attribute to the global layout, the browser would start caching all the pages as the global layout is applicable to all the view pages of the site. Remedy is to create a separate custom layout for the page to be cache with the only difference from the global layout being that the HTML opening tag would have the manifest attribute.

Adding manifest attribute on the page to be cached implies its a master entry in HTML5 offline parlance.

3. Add all the supporting assets of the view to be rendered like css, jpg etc in the manifest file like so –

http://localhost/appname/assets/52baada/lang/calendar-en.js

Doing so would make these as explicit entries for HTML5 manifest.

That’s it, try on the browser. On Chrome,

1. view your page as part of application cache in Developer Tools -> Resources

2. For detailed view and option to remove, access chrome://appcache-internals/

3. Also, there is a manifest validator at http://manifest-validator.com/

Resources:

  1. http://diveintohtml5.info/offline.html
  2. http://www.webdirections.org/blog/get-offline/
  3. http://www.whatwg.org/specs/web-apps/current-work/#applicationcache
  4. http://www.html5rocks.com/en/tutorials/appcache/beginner/#toc-introduction
  5. https://developer.mozilla.org/en/offline_resources_in_firefox

Using app cache in JavaScript-

  1. http://www.bennadel.com/blog/2029-Using-HTML5-Offline-Application-Cache-Events-In-Javascript.htm
  2. https://developer.apple.com/library/safari/#documentation/iPhone/Conceptual/SafariJSDatabaseGuide/OfflineApplicationCache/OfflineApplicationCache.html