In order to allow developer to use translator instance into validators, Zend Framework 2.2 add a new service call MvcTranslator, as quoted in documentation:

“A new service has also been registered with the MVC, MvcTranslator, which will return this specialized, bridge instance.

Most users should see no issues, as Zend\Validator\ValidatorPluginManager has been modified to use the MvcTranslator service internally, which is how most developers were getting the translator instance into validators in the first place. You will only need to change code if you were manually injecting the instance previously.”

However, we used to set the locale by a manually injected translator to allow users switching to different languages. After upgraded to 2.2.2 or later (the latest version at this time is 2.3.1), the switching languages function is no longer working properly.

In order to make sure function works properly no matter the version is, I updated the code to something like:

    public function setLocale($locale) {
        $sm = $this->getServiceLocator();
            $this->translator = $sm->get('mvcTranslator');
        }else if($sm->has("Translator")){
            $this->translator = $sm->get('translator');

Some content on this page was disabled on March 8, 2018 as a result of a DMCA takedown notice from Yahoo!. You can learn more about the DMCA here:


Continue Reading »

Twitter Typeahead is a fast and effective auto-complete jQuery plugin for form filling.

Twitter Typeahead 插件是一個jQuery 插件,用作快速而有效率的自動填表工具。

In desktop computer, this plugin (Twitter Typeahead) works properly. However, when this plugin is run on a mobile computer, it cannot detect the “blur” event properly. The suggested text cannot be closed when you click outside the suggestion box.

在正常的桌面電腦上,這個Twitter Typeahead插件能正常地運作。可是,一旦放在手機的瀏覽器上運行,卻因無法捕捉到“blur”的事件。如果輕觸瀏覽器的其他地方,無法可以正常關閉“提示列”。

One of the possible method is add a close button “x” to close the suggestion list. I’ve done an ugly example illustrate this: typeahead with close button “x”

其中一個可行的方法,就是在提示清單上加入一個關閉的按鈕”x”,小弟做了個核突的版本:typeahead with close button “x”

What you need to do is to change line 849:

 dropdown: '<span class="tt-dropdown-menu"></span>'


 dropdown: '<span class="tt-dropdown-menu"><a class="tt-dropdown-close" onclick="$(this).closest(\'span\').hide()">x</a></span>'

If you feel this screen is ugly, what you need is to add CSS file.

如果您在使用Google DoubleClick for publsher(DFP Ad,Google 提供的公開的點擊廣告統計)來管理您自己網站的廣告。在時發覺看不到廣告時,總想找出問題的原因。Google DoubleClick for publisher所使用的程式碼叫做Google Publisher Tag,在運行過程中,會將所發生的問題的時間、狀況記錄下來。

If you are using “Google DoubleClick for publisher” to manage your own advertisement in your website, sometimes you may want to find out the reasons behind when your ads don’t work. The library for managing “Google DoubleClick for Publisher” is called “Google Publisher Tag”. During the operation of “Google Publisher Tag”, every error will be logged into its own logging system.

要如何查看Google Publisher Tag的運行的記錄呢?它放置在googletag.getEventLog().H之內。

The “Google Publisher Tag” store the event log in googletag.getEventLog().H

用Google Chrome打開Console打入以下的指令:
Use google chrome and turn on the “Console” and enter the following command:


Google Publisher Tag Log

If you have installed mac port, it’s normal to install python and django under macport.


The latest python installed by macport should be 2.7.3, thus command for installation of python and django are:


sudo port install python
sudo port install py27-django

If you have installed previous version of python through macport, you should make sure which one is active, you can use the following command to check:


port select --list python

The result should be similar to the following:

Available versions for python:
	none (active)

If you want to ask macport to select the python 2.7.3 provided by macport as default python interpreter, you should use the following command:

如果你想指定用macport所提供的python 2.7,你需要用到以下的指令:

sudo port select python python27

If you want to see if you have set the active python interpreter correctly, type the following command to check the path of python:

如果你想測試之前能否成功地指定python interpreter,可以用以下的指令查看python的路徑:

which python

If you selected macport’s python, the path should be:


Try to repeat the previous steps if you find the path is different.

Now, please check your path to django-admin.py:

which django-admin.py

In my computer, the result is:


If you execute django-admin.py, you will find out that python cannot find django.core. The problem is caused from the first line of django-admin.py


from django.core import management

if __name__ == "__main__":

The first line tell shell to use the python installed by mac os instead of using the python provided by macport. Thus, we should use the following command to change the first line:
第一句告知shell使用由mac os所提供的python而不是macport 所提供的python。所以我們須用以下的指令更改第一句:

sudo nano /usr/local/bin/django-admin.py

The updated source code should look like:

from django.core import management

if __name__ == "__main__":

Then, you can ran django-admin.py properly.

However, next time if you update django, please repeat the process again.

One of my colleague using Internet Explorer 10 to emulate IE 8 Standard mode. During calling slice() method for a String object. It shows the error “slice not found in object”.

我有位同事用Internet Explorer 10去模擬IE 8標準模式。在一句指令中,字串物件上執行slice()方法時,卻發生了問題,Internet Explorer顯示”slice not found in object”

This problem in weird since in microsoft website, it stated that string’s slice method is existed in all versions. (http://msdn.microsoft.com/en-us/library/ie/s4esdbwz(v=vs.94).aspx)
這是個奇怪的情況,因為在微軟的網站內寫著所有版本Internet Explorer都有String slice。

In order to avoid any similar problem, I wrote a custom slice() method whenever slice() is not found as default:

if(typeof String.prototype["slice"]==="undefined"){String.prototype.slice=function(s,e){var l=this.length;return this.substr(s=s<0?l+s:s,typeof e==='number'?(e<0?l+e:e)-s:l-s)}}