Dojo Ajax Combo box in Zend Framework: Creating Ajax combo box using dojo in zend framework

9 Jan

Damn it. I wasn’t even imagining that Zend team has done such a wonderful job for creating ajax enabled application. Last night I was amazed by dojo grid and today by combo box.

I don’t have words to appreciate Zend developers.

Lets see how much time and efforts it takes to make a fabulous ajax enabled combo box using dojo and zend framework.

Create a controller and place the following code


class TestController extends Zend_Controller_Action


function indexAction()


$form= new Zend_Dojo_Form();





‘label’       => ‘ComboBox (datastore)’,

‘storeId’     => ‘stateStore’,

‘storeType’   => ‘’,

‘storeParams’ => array(

‘url’ => ‘records’,


‘dijitParams’ => array(

‘searchAttr’ => ‘name’,






function recordsAction()



$sql = ‘SELECT * FROM company’;

$result = $db->fetchAll($sql);

$dojoData= new Zend_Dojo_Data(‘id’,$result,’id’);

echo $dojoData->toJson();




We define our form as

$form = new Zend_Dojo_Form();


And combo box element to it. Few of it properties are important, such as storeId, storeType and storeParams. In the store Params we have given the url of the action.

Next we define our action which fetch data form the table and create Json response for us. That’s it we have done.

In view/scripts/index.phtml, only write

<? echo $this->form?>


Only one thing. Write following lines in your layout file

<? $this->dojo()->setDjConfigOption(‘usePlainJson’,true)




echo $this->dojo();


That’s it.  You will now see a nice and beautiful combo box sending ajax request and fetching data on the fly.


One Response to “Dojo Ajax Combo box in Zend Framework: Creating Ajax combo box using dojo in zend framework”

  1. chonny March 13, 2009 at 10:43 am #

    This example doesn’t work with zend 1.7.6 and dojo 1.2.3.
    I’ve spent 2 days to resolve problem without success 😦

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: