Skip to content

Instantly share code, notes, and snippets.

@taleeb35
Created September 16, 2014 06:45
Show Gist options
  • Select an option

  • Save taleeb35/edcb24d9fc134a14ebda to your computer and use it in GitHub Desktop.

Select an option

Save taleeb35/edcb24d9fc134a14ebda to your computer and use it in GitHub Desktop.
<?php
App::uses('AppController', 'Controller');
class CountriesController extends AppController {
public $helpers = array('Js');
public function select() {
$countries = $this->Country->find('list');
$states = array();
foreach ($countries as $country_id => $name) {
$states = $this->Country->State->findByCountryId($country_id);
break;
}
$this->set(compact('countries', 'states'));
}
public function states_list() {
$this->request->onlyAllow('ajax');
$id = $this->request->query('id');
if (!$id) {
throw new NotFoundException();
}
$states = $this->Country->State->find('list', array(
'conditions' => array('country_id' => $id)
));
$this->set(compact('states'));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment