-1

I want to create a dropdown list with data from a relational table. I have a tbl_stock, and on that table I have a relation to other table typeStock, and these connection mades the "type of stock" on the tbl_stock.

So I want to create a dropdownList in the form.

I already tried something like this:

in the controller:

 protected function getStockOptions(){
            $stockArray = CHtml::listData(Stock::model()->findAll(), 'id', 'tipo');
            return $stockArray;

        }

in the _form.php view:

<?php echo $form->dropDownList($model,'tipo', Stock::model()->findAll()); ?>

I can't find a way for this to work, now It's getting a error "stock could not be converted to string".

niac
  • 33
  • 2
  • 17
  • Why you're using `Stock::model()->findAll()` in view instead of `getStockOptions()` result? – rob006 Apr 02 '19 at 14:21

1 Answers1

0

try this:

echo $form->dropDownList($model,'tipo', CHtml::listData(Stock::model()->findAll(),'id','tipo'));

niac
  • 33
  • 2
  • 17