When Drop down is changed then Ajax call to controller is used. This Ajax call hits to server and get data from database.
Here is code some of code snippet to for ajax call. This ajax call is handled in view of zend framework

echo $this->formLabel($Form->get(‘country’));
echo $this->formSelect($Form->get(‘country’));

This code snippet is to render country dropdown. When country is selected from country then Ajax is called.
here is ajax code

var country_id = $(this).val();
url : “<?php echo($this->url(‘property’, array(‘action’ => ‘fetchStates’, ‘controller’ => ‘Property’))); ?>”,
type : “POST”,
data : {country_id:country_id},
cache : false,
success :
var arr = $.parseJSON(result);
var str = ‘<option></option>’;
$.each(arr, function(key, value) {
str += ‘<option value=”‘+key+'”>’;
str += value;
str += ‘</option>’;

When country is selected from dropdown then controller PROPERTIES is called .and fetchCities action from this controller is called.
Here is code of the fetchCities action that brings data from database.
    private function fetchCities()
$cList = array();
$C = $this->getServiceLocator()->get(‘EntityManager’)->getRepository(‘AdministrationEntityCity’)->findAll();
if (count($C))
foreach ($C as $City)
$cList[$City->getId()] = $City->getName();
return $cList;

doctrine is being used in zend framework that interacts with database. getRepository function is used that uses findAll function to bring List of related cities of respective coutnry.

Leave a Reply

Your email address will not be published. Required fields are marked *