admin管理员组文章数量:1428520
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
1 Answer
Reset to default 7Since 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.
本文标签: phpComposite CHtmllistData valueStack Overflow
版权声明:本文标题:php - Composite CHtml::listData value - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745528872a2661967.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论