dortmundbvb0624 2013-07-05 22:24
浏览 75
已采纳

从相关表创建下拉列表yii

I have two tables: product and product_type (related to the models resp. Product and Product_type):

product : product_id, product_type_id, name, etc...
product_type : product_type_id, name, desc, etc...

Both are related with key "product_type_id".

I have created the crud for both tables using gii crud generator. Now on Product form page I want to display the listing of all product_type name in dropdown field using Yii ActiveRecord. I have added this line in views/product/_form.php script:

<?php
    $list = CHtml::listData(ProductType::model()->findAll(array('order' => 'product_type_name')), 'id', 'id');
    echo $form->dropDownList($model, 'product_type_id', $list);
?>

But it's showing blank dropdown field :(

How can I do this?

  • 写回答

3条回答 默认 最新

  • dty97501 2013-07-05 23:18
    关注

    Solved MySelf :)

    By just providing product_type_name.

    <?php
            $list = CHtml::listData(ProductType::model()->findAll(array('order' => 'product_type_name')), 'product_type_id', 'product_type_name');
            echo $form->dropDownList($model, 'product_type_id', $list);
            ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部