php - Composite CHtml::listData value - Stack Overflow

I want to post group value in a drop down. How do i concate id and group (type) in value field?CHtml::l

I want to post group value in a drop down. How do i concate id and group (type) in value field?

CHtml::listData($eventLocationByUser, 'id', 'caption', 'type');

I have tried:

CHtml::listData($eventLocationByUser, 'id'.'type', 'caption', 'type');

but returning empty value.

I want to post group value in a drop down. How do i concate id and group (type) in value field?

CHtml::listData($eventLocationByUser, 'id', 'caption', 'type');

I have tried:

CHtml::listData($eventLocationByUser, 'id'.'type', 'caption', 'type');

but returning empty value.

Share Improve this question asked May 31, 2013 at 0:37 Wildan MuhlisWildan Muhlis 1,6133 gold badges25 silver badges45 bronze badges 1
  • 1 check this stackoverflow./questions/12812062 – dInGd0nG Commented May 31, 2013 at 13:26
Add a ment  | 

1 Answer 1

Reset to default 7

Since the value field accepts an anonymous function you can do it like this:

CHtml::listData( 
    $eventLocationByUser, 
    'id', 
    function($loc){ return $loc->id . " " . $loc->type; }
);

And here is the example from the docs.


One alternative way could be to add another field to your model (lets say $idtype for example), and every time you create or save a record you update this field as well (using a behavior perhaps?) And then you can use:

CHtml::listData( $eventLocationByUser, 'id', 'idtype' });

It could potentially move business logic from your view to your model, but only you can decide if it's worth the hassle.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745528873a4631601.html

相关推荐

  • php - Composite CHtml::listData value - Stack Overflow

    I want to post group value in a drop down. How do i concate id and group (type) in value field?CHtml::l

    1天前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信