在Yii框架下拉列表中添加创建新链接

在Yii框架下拉列表中添加创建新链接,yii,Yii,我是Yii框架的新手,在Yii框架中做一个小应用程序,我有发票和客户的数据库 ==== Invoice ==== id customer_id invoice_title invoice_no invoice_issue_date created_by updatd_by === Customers === id customer_name address business_address city st

我是Yii框架的新手,在
Yii框架
中做一个小应用程序,我有
发票
客户的数据库

   ==== Invoice ====
   id
   customer_id
   invoice_title
   invoice_no
   invoice_issue_date
   created_by
   updatd_by

   === Customers ===
   id
   customer_name
   address
   business_address
   city
   state
<div class="row">
<?php echo $form->labelEx($customers,'customer_name'); ?>
<?php echo $form->dropdownList($customers,'customer_name', CHtml::listData(Customers::model()->findAll(), 'id', 'customer_name'), array('empty'=>'Choose one')); ?>
<?php echo $form->error($customers,'customer_name'); ?>
</div>
$form->dropdownList($customers,'customer_name', CHtml::listData(Customers::model()->findAll(), 'id', 'customer_name'), array('empty'=>array('choose'=>'Choose one','new'=>'New Client')))
现在根据我的要求,我需要发票创建表单中的所有可用客户名称应位于
下拉列表中,因此我在
Invoice form.php
中进行了更改,以这样调用所有可用客户名称

   ==== Invoice ====
   id
   customer_id
   invoice_title
   invoice_no
   invoice_issue_date
   created_by
   updatd_by

   === Customers ===
   id
   customer_name
   address
   business_address
   city
   state
<div class="row">
<?php echo $form->labelEx($customers,'customer_name'); ?>
<?php echo $form->dropdownList($customers,'customer_name', CHtml::listData(Customers::model()->findAll(), 'id', 'customer_name'), array('empty'=>'Choose one')); ?>
<?php echo $form->error($customers,'customer_name'); ?>
</div>
$form->dropdownList($customers,'customer_name', CHtml::listData(Customers::model()->findAll(), 'id', 'customer_name'), array('empty'=>array('choose'=>'Choose one','new'=>'New Client')))

它正在工作,但我希望
在下拉列表中创建客户
链接,而不是在下拉列表之外。因此,如何做到这一点?任何帮助和建议都将非常值得欣赏。

您可以创建一个带有标签New Client的空选择项,如下所示

   ==== Invoice ====
   id
   customer_id
   invoice_title
   invoice_no
   invoice_issue_date
   created_by
   updatd_by

   === Customers ===
   id
   customer_name
   address
   business_address
   city
   state
<div class="row">
<?php echo $form->labelEx($customers,'customer_name'); ?>
<?php echo $form->dropdownList($customers,'customer_name', CHtml::listData(Customers::model()->findAll(), 'id', 'customer_name'), array('empty'=>'Choose one')); ?>
<?php echo $form->error($customers,'customer_name'); ?>
</div>
$form->dropdownList($customers,'customer_name', CHtml::listData(Customers::model()->findAll(), 'id', 'customer_name'), array('empty'=>array('choose'=>'Choose one','new'=>'New Client')))
并且有一个jquery功能备用,如果选择了“新客户机”,就会触发一个lightbox弹出窗口

$('your_select').change(function(){
  if($(this).val() == 'new') {
   // do something
  }
})
更新以反映您的更新

<?php 
  echo $form->dropDownList(
                     $customers,'customer_name',
                     CHtml::listData(Customers::model()->findAll(), 'id', 'customer_name'),
                     array('prompt'=>'Select', 'empty'=>array('choose'=>'Choose'), 'id'=>'customersSelect')
              ); 
?>

<script type='text/javascript'>
   $(document).ready(function(){
       $('#customersSelect').change(function(){
          if($(this).val() == 'choose') {
             $("#customers").dialog("open");
          }
       });
    });
</script>

$(文档).ready(函数(){
$('#CustomerSelect')。更改(函数(){
if($(this).val()=='choose'){
$(“#客户”)。对话框(“打开”);
}
});
});

在这一行
$form->dropdownList($customers,'customer\u name',CHtml::listData(customers::model()->findAll(),'id','customer\u name'),数组('empty'=>数组('=>'Choose one','new=>'new Client'))
新客户端
在下拉列表中不可见。我想这是因为我没有向第一个选项添加值。另外,在最后缺少一个括号。更新后,请立即尝试:)您更新的代码无效。它没有显示“新建客户端”选项。请尝试使用CHtml::dropDownList而不是ActiveForm的dropDownList。TBH,我用前者测试了代码。正如我所说,您可以在select中有多个空白项,如果选择了一个特定项,则可以使用javascript显示/隐藏对话框窗口。我更新了我的答案,再清楚不过了。