Archives for programming languages

all about programming language

PHPUnit, treat our programmer better

While no doubt PHPUnit is an excellent project, today i was so frustrated because of it. Look at the following code, first I declared an mock then defined some behavior of the mock. Since I did some re-factoring and use CatetoryId instead of Category here, I renamed mock method from ‘getCategory’ to ‘getCategoryId’. Then when [...]

Send complex json request

As using Backbone.js I wanted to send a whole JSON object to the back end, which is implemented with Zend Framework. Tim White has written a very good article about it. What I have done is converting the JSON object to a string and send it per POST to the back end. Then let back [...]

Magento cache

If your/var/cache has not write right for www-data, magento will save the cache file into /tmp/magento/var/cache

clone an php object

Array and Object in PHP are all reference. If you assign a variable with an array or an object, this variable is a reference of that array/object. Using clone you can copy an object. php> class a { public $name; public function __costruct($name) {$this->name = $name;}} php> $a = new a(‘wang’); php> $b = $a; [...]

Zend Controller in Ajax Context Testing

We can use AjaxContext action helper to define a context of an action. public function init() { $ajaxContext = $this->_helper->getHelper(‘AjaxContext’); $ajaxContext->addActionContext(‘get-zip-code’, ‘json’) ->initContext(); } public function getZipCodeAction() { // that is all! you don’t need to do any for json encode $this->view->zip = ’123′; } Since we use AjaxContext then we don’t need to create [...]

js is weird

Create dijit declaratively

Using programmatically way to create a dijit is flexible and clear. You can use this dijit as an object after creating. var btn = new dijit.form.Button({label: ‘click me’}); Sometime we have to create dijit declaratively. In order to do some initialization works or connect a callback function to the dijit or override a function of [...]

Using Sha512 with Zend_Auth

Normally we can use setCredentialTreatment(‘MD5(?)’); or setCredentialTreatment(‘SHA1(CONCATE(?, salt))’); to encode the password. But sha1 and MD5 has security flaws and shouldn’t be used for new application. MySQL 5.1 doesn’t support SHA2 (MySQL 5.5 has function about SHA2) we have to encode the user input by ourselves. The way is to write a calss extends Zend_Auth_Adapter_DbTable. [...]

get php 5.3.6 with iconv on snow leopard

In order to generate Captcha with Zend Framework the php needs to be compiled with the option freetype. But the php shiped by snow leopard is compiled without this option. To solve this problem I have to compile the PHP myself. But there is always problem when PHP is compiled with the option iconv. After [...]

Enable dojo for a zend project

To enable dojo in your zend framework project is quit easy by using application resource. What you need to do is just add the following code into your application.ini resources.layout.layoutPath = APPLICATION_PATH “/layouts/scripts” resources.layout.layout = “layout” resources.dojo.enable = true resources.dojo.djConfig.parseOnLoad = 1 resources.dojo.localPath= “/js/dojo/dojo.js” resources.dojo.registerdojostylesheet = true resources.dojo.requireModule[] = “dojo.io.script” resources.view.encoding = “UTF-8″ resources.view.basePath = [...]