Hi…
I have a problem with method findAll(). I want to use method findAll to fill my dropdown list with CHtml::listData.
this is my code in the _form:
<div class="form-group">
<?php echo $form->labelEx($model,'id_skpd'); ?><br>
<?php
$opt_skpd = CHtml::listData($skpd,'id_skpd','nama_skpd');
echo Chosen::dropDownList('Program[id_skpd]', $model->id_skpd, $opt_skpd, array('empty' => '','data-placeholder'=>'Pilih Skpd','class'=>'form-control','style'=>'max-width: 300px')); ?>
</div>
and this is my actionCreate function in the controller:
public function actionCreate()
{
$model=new Program;
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if(isset($_POST['Program']))
{
$model->attributes=$_POST['Program'];
if($model->save())
$this->redirect(array('view','id'=>$model->id_program));
}
$this->render('create',array(
'model'=>$model,
'skpd'=>Skpd::model()->findAll()
));
}
but when I test, there is only one data appears. whereas in the database there are two data.
I have also been tested by printing the results of method findAll earlier by:
$opt_skpd = CHtml::listData($skpd,'id_skpd','nama_skpd');
print_r($opt_skpd);
and the result is like this:
array(
[] => 'Dinas Pendidikan'
)
I do not understand what is wrong with the code that I created. Please help me…
Thank You.