douhu2131 2015-10-01 06:31
浏览 58
已采纳

是否有可能将内容从cgridview显示为yii中的下拉列表?

I have modified my model so that the data displayed in cgridview is unique per user, depending on the account type...

However I need to create a form from another model where I could get the data from the cgridview via dropdown...

I used this code at first...

<?php 
$this->widget('ext.select2.ESelect2',array(
  'model'=>$model,
  'attribute'=>'pr_id',
  'data'=>$model->searchPatient(),//function to provide data
  // or
  //'data'=>CHtml::listData(PatientRecord::model()->findAll(), 'id', 'first_name')
);  
?>

but it returns all of the contents of the PatientRecord model, I tried using a condition before planning to retrieve the contents from the cgridview...

$doctor= Yii::app()->user->id;
CHtml::listData(PatientRecord::model()->findAll( array(
                                'condition'=>'doctor_id=:doctor_id', 
                                'params' => array(':doctor_id' => $doctor)
                             )
                    );), 'id', 'first_name')

it didn't have an error but it didn't display anything on the dropdown either...

any suggestions?

  • 写回答

1条回答 默认 最新

  • dougou8639 2015-10-01 07:35
    关注

    I think the problem is with a ; and ) in your model code, try this:

       $doctor= Yii::app()->user->id;
       CHtml::listData(PatientRecord::model()->findAll( array(
                                        'condition'=>'doctor_id=:doctor_id', 
                                        'params' => array(':doctor_id' => $doctor)
                                     )
                            ), 'id', 'first_name');
    

    You should always enable error logging in local environment, this will help you find any errors in your code. Here is a link on how to enable error logging.

    Hope that helps :)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?