根据Cakephp中的国家/地区添加州列表

时间:2012-12-20 14:03:36

标签: cakephp

在控制器中,我有更新地址的功能

    if(!empty($this->data)) {
        $this->data['Address']['user_id'] = $this->Auth->user('id');
        $this->data['Address']['user_address_type_id'] = $address_type_id;
        if($this->Address->save($this->data)) {
            if(!empty($this->data['Address']['update_all'])) {
                $this->Address->updateAll($this->data);
            }
            $this->Session->setFlash(__('The address was successfully updated.', true), 'default', array('class' => 'success'));
            $this->redirect(array('action'=>'index'));
        } else {
            $this->Session->setFlash(__('There was a problem updating the address, please correct the errors below.', true));
        }
    } else {
        $this->data = $this->Address->find('first', array('conditions' => array('user_address_type_id' => $address_type_id, 'user_id' => $this->Auth->user('id'))));
    }


    $this->set('countries', $this->Address->Country->find('list',array('order' => 'Country.name ASC')));    

并在edit.ctp文件中

                <fieldset>
                    <legend><?php __('Update Address');?></legend>
                <?php

                    echo $form->input('id');
                    echo $form->input('name', array('label' => __('Name *', true)));
                    echo $form->input('address_1', array('label' => __('Address (line 1) *', true)));
                    echo $form->input('address_2', array('label' => __('Address (line 2)', true)));
                    echo $form->input('suburb', array('label' => __('Suburb / Town', true)));
                    echo $form->input('city', array('label' => __('City / State / County *', true)));
                    echo $form->input('postcode', array('label' => __('Post Code / Zip Code *', true)));
                    echo $form->input('country_id', array('label' => __('Country *', true), 'empty' => 'Select'));
                    echo $form->input('state_id', array('type' => 'select','label' => __('States *', true), 'empty' => 'Select'));              
                    echo $form->input('phone', array('label' => __('Phone', true)));
                    /*echo $form->input('update_all', array('type' => 'checkbox', 'label' => __('Make all your addresses this address.', true)));*/
                ?>
                </fieldset>

我想根据所选国家/地区添加州名单。例如,如果选择USA,那么美国州将出现在州下拉等状态

0 个答案:

没有答案