<tfoot id='vEX6G'></tfoot>
      <bdo id='vEX6G'></bdo><ul id='vEX6G'></ul>

      <i id='vEX6G'><tr id='vEX6G'><dt id='vEX6G'><q id='vEX6G'><span id='vEX6G'><b id='vEX6G'><form id='vEX6G'><ins id='vEX6G'></ins><ul id='vEX6G'></ul><sub id='vEX6G'></sub></form><legend id='vEX6G'></legend><bdo id='vEX6G'><pre id='vEX6G'><center id='vEX6G'></center></pre></bdo></b><th id='vEX6G'></th></span></q></dt></tr></i><div id='vEX6G'><tfoot id='vEX6G'></tfoot><dl id='vEX6G'><fieldset id='vEX6G'></fieldset></dl></div>
      <legend id='vEX6G'><style id='vEX6G'><dir id='vEX6G'><q id='vEX6G'></q></dir></style></legend>

      <small id='vEX6G'></small><noframes id='vEX6G'>

      Yii的依赖下拉框

      时间:2023-09-24
    1. <i id='Wq2cm'><tr id='Wq2cm'><dt id='Wq2cm'><q id='Wq2cm'><span id='Wq2cm'><b id='Wq2cm'><form id='Wq2cm'><ins id='Wq2cm'></ins><ul id='Wq2cm'></ul><sub id='Wq2cm'></sub></form><legend id='Wq2cm'></legend><bdo id='Wq2cm'><pre id='Wq2cm'><center id='Wq2cm'></center></pre></bdo></b><th id='Wq2cm'></th></span></q></dt></tr></i><div id='Wq2cm'><tfoot id='Wq2cm'></tfoot><dl id='Wq2cm'><fieldset id='Wq2cm'></fieldset></dl></div>
      <tfoot id='Wq2cm'></tfoot>
        <bdo id='Wq2cm'></bdo><ul id='Wq2cm'></ul>
      • <small id='Wq2cm'></small><noframes id='Wq2cm'>

            <legend id='Wq2cm'><style id='Wq2cm'><dir id='Wq2cm'><q id='Wq2cm'></q></dir></style></legend>

                  <tbody id='Wq2cm'></tbody>

                本文介绍了Yii的依赖下拉框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我有一个国家、州、城市表,我需要 3 个下拉菜单其中,如果我选择一个国家,例如美国,州下拉菜单将自动只显示美国下的州,接下来,如果我选择一个州,例如加利福尼亚,城市下拉菜单将只显示美国加利福尼亚以下的城市

                我目前在 yii 中实现这个有问题.我有这个 _form 文件应包括这 3 个下拉列表.我有部分代码,但我不知道如何解决

                这是来自控制器

                公共函数 actionDynamicstates(){$sql = "SELECT StateName FROM gg_t_worldareasstates "."WHERE CountryID = :countryid";$command = Yii::app()->createCommand($sql);$command->bindValue(':countryid', $_POST['CountryID'], PDO::PARAM_INT);$data = $command->execute();$data = CHtml::listData($data,'StateID','StateName');foreach($data as $value=>$name){echo CHtml::tag('选项',array('value'=>$value),CHtml::encode($name),true);}}

                这是来自_form视图文件

                <?php$country = 新的 CDbCriteria;$country->order = 'CountryName ASC';echo $form->dropDownList($model, 'CountryID',CHtml::listData(Worldareascountries::model()->findAll($country),'国家ID',大批('阿贾克斯' =>大批('类型' =>'邮政','网址' =>CController::createUrl('wsmembersdetails/dynamicstates'),'更新' =>'#StateID',))));echo $form->dropDownList('StateID','', array());?>

                我把上面的那些代码改成了这个

                 

                <?php echo $form->labelEx($model,'Country');?><?php$country = 新的 CDbCriteria;$country->order = 'CountryName ASC';?><?phpecho $form->dropDownList($model,'CountryID',CHtml::listData(Worldareascountries::model()->findAll($country),'CountryID','CountryName'),大批('阿贾克斯' =>大批('类型' =>'邮政','网址' =>CController::createUrl('wsmembersdetails/dynamicstates'),'更新' =>#StateID")));?><?php echo $form->error($model,'CountryID');?>

                <div class="row"><?php echo $form->labelEx($model,'State');?><?php$state = 新的 CDbCriteria;$state->order = 'StateName ASC';?><?phpecho $form->dropDownList($model,'StateID',CHtml::listData(Worldareasstates::model()->findAll($state),'StateID','StateName'),大批('阿贾克斯' =>大批('类型' =>'邮政','网址' =>CController::createUrl('wsmembersdetails/dynamiccities'),'更新' =>'#CityID')));?><?php echo $form->error($model,'StateID');?>

                <div class="row"><?php echo $form->labelEx($model,'CityID');?><?php echo $form->dropDownList($model,'CityID','',array());?><?php echo $form->error($model,'CityID');?>

                解决方案

                这个问题已经解决,在 yii wiki 文档上

                i have a countries, states, cities tables , and I need 3 dropdown menus wherein, if i select a country like e.g United States, the states dropdown menu will automatically show only the states that are under United States, and next, if I select a State like e.g California, the Cities drop down menu will only show off the Cities under California

                am currently having problem implementing this in yii. I have this _form file where these 3 dropdown should be included. I have a partial code, but I can't figure out how to make this work out

                this is from the Controller

                public function actionDynamicstates()
                {
                  $sql = "SELECT StateName FROM gg_t_worldareasstates ".
                         "WHERE CountryID = :countryid";
                  $command = Yii::app()->createCommand($sql);
                  $command->bindValue(':countryid', $_POST['CountryID'], PDO::PARAM_INT);
                  $data = $command->execute();
                
                  $data = CHtml::listData($data,'StateID','StateName');
                  foreach($data as $value=>$name)
                  {
                    echo CHtml::tag('option',
                    array('value'=>$value),CHtml::encode($name),true);
                  }
                }
                

                this is from the _form view file

                <div class="row">
                <?php 
                $country = new CDbCriteria; 
                $country->order = 'CountryName ASC';
                echo $form->dropDownList($model, 'CountryID', 
                  CHtml::listData
                  (
                    Worldareascountries::model()->findAll($country),
                    'CountryID',
                    array
                    (
                      'ajax' => array
                      (
                        'type' => 'POST',
                        'url' => CController::createUrl('wsmembersdetails/dynamicstates'),
                        'update' => '#StateID',
                      )
                    )
                  )
                );
                echo $form->dropDownList('StateID','', array());
                ?>
                </div>
                

                I changed that those codes above into this one

                    <div class="row">
                    <?php echo $form->labelEx($model,'Country'); ?>
                    <?php 
                          $country = new CDbCriteria; 
                          $country->order = 'CountryName ASC';
                    ?>
                    <?php 
                          echo $form->dropDownList($model,'CountryID',CHtml::listData(Worldareascountries::model()->findAll($country),'CountryID','CountryName'),
                                    array(
                                        'ajax' => array(
                                        'type' => 'POST',
                                        'url' => CController::createUrl('wsmembersdetails/dynamicstates'),
                                        'update' => "#StateID"
                                    )       
                              )
                          );
                    ?>
                    <?php echo $form->error($model,'CountryID'); ?>
                </div>
                
                <div class="row">
                    <?php echo $form->labelEx($model,'State'); ?>
                    <?php 
                          $state = new CDbCriteria;
                          $state->order = 'StateName ASC';
                    ?>
                    <?php 
                          echo $form->dropDownList($model,'StateID',CHtml::listData(Worldareasstates::model()->findAll($state),'StateID','StateName'),
                                    array(
                                        'ajax' => array(
                                        'type' => 'POST',
                                        'url' => CController::createUrl('wsmembersdetails/dynamiccities'),
                                        'update' => '#CityID'
                                    )   
                                )
                          );
                    ?>
                    <?php echo $form->error($model,'StateID'); ?>
                </div>
                
                
                <div class="row">
                
                    <?php echo $form->labelEx($model,'CityID'); ?>
                     <?php echo $form->dropDownList($model,'CityID','',array());?>
                    <?php echo $form->error($model,'CityID'); ?>
                

                解决方案

                this problem was solved, it's on the yii wiki docs

                这篇关于Yii的依赖下拉框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:有人可以解释 Yii 最小化资产应该如何在 Heroku 上工作吗? 下一篇:使用 crontab 在 yii 中添加剩余电子邮件

                相关文章

                  <bdo id='zMli4'></bdo><ul id='zMli4'></ul>

                  <i id='zMli4'><tr id='zMli4'><dt id='zMli4'><q id='zMli4'><span id='zMli4'><b id='zMli4'><form id='zMli4'><ins id='zMli4'></ins><ul id='zMli4'></ul><sub id='zMli4'></sub></form><legend id='zMli4'></legend><bdo id='zMli4'><pre id='zMli4'><center id='zMli4'></center></pre></bdo></b><th id='zMli4'></th></span></q></dt></tr></i><div id='zMli4'><tfoot id='zMli4'></tfoot><dl id='zMli4'><fieldset id='zMli4'></fieldset></dl></div>
                1. <legend id='zMli4'><style id='zMli4'><dir id='zMli4'><q id='zMli4'></q></dir></style></legend>

                  1. <small id='zMli4'></small><noframes id='zMli4'>

                    <tfoot id='zMli4'></tfoot>