Image Yii根据下拉列表动态显示图像

Image Yii根据下拉列表动态显示图像,image,yii,Image,Yii,我试图显示图像,但依赖于Yii中的下拉列表。我可以从数据库中获取图像并显示它,但是如何根据下拉列表中的选择动态地执行此操作?这里是参考:但是,让我演示如何执行此操作 首先,我们需要一个显示图像的div;我将创建一个id为“img”的。然后,在dropdownlist()中指定ajax请求,如下所示: <?php echo $form->labelEx($model,'attribue'); ?> <?php echo $form->dropDownList($mod

我试图显示图像,但依赖于Yii中的下拉列表。我可以从数据库中获取图像并显示它,但是如何根据下拉列表中的选择动态地执行此操作?

这里是参考:但是,让我演示如何执行此操作

首先,我们需要一个显示图像的div;我将创建一个id为“img”的。然后,在dropdownlist()中指定ajax请求,如下所示:

<?php echo $form->labelEx($model,'attribue'); ?>
<?php echo $form->dropDownList($model,'attribute',
array(/*The options in the DropDownList*/),
array(
          'ajax'=>array(
             'type'=>'POST',
             'url'=>CController::createUrl('YourController/actionWhichEchoesTheImage'),
             'update'=>'#img',
))); 
?>

<div id="img">   // <---- the result of the ajax call will be displayed here
</div> 

检查CHtml::image()此处:

信息不足,但您需要预加载所有图像,或者在每次更改下拉列表时进行AJAX调用。对不起,每次更改下拉列表时,我都需要它进行AJAX调用。感谢您的回复。如果下拉列表已经有AJAX操作,该怎么办,我可以调用两个单独的操作并更新该div和另一个下拉列表吗?是的,这是可能的,但需要一些jQuery代码。我必须告诉你,从我的观点来看,那完全是另一个问题。你也许可以把它寄出去。这将是一个好的。
    public function actionWhichEchoesTheImage()
   {
      if(isset($_POST['ModelName']['attribute']))
         /*Here goes your code to load the image*/
         echo CHtml::image(//Check the reference to see how to set this function); 
   }