Search code examples
phpyiicgridviewdropdown

is it possible to display content from cgridview to dropdown in 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?


Solution

  • 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 :)