<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的依赖下拉框

      dependent dropdown box with Yii(Yii的依赖下拉框)
    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的依赖下拉框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
                PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
                mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
                Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
                Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
                Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)
                  <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>
                    • <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>

                          <tbody id='zMli4'></tbody>