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".