Created
September 16, 2014 06:45
-
-
Save taleeb35/edcb24d9fc134a14ebda to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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