0

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

    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,则 USA States 会出现在 states 下拉列表中等。

4

0 回答 0