kazio
(Kontakt)
1
maybe somebody find it usefull
in helpers dir: UHTml.php
<?php
class UHtml {
public function listData($model, $value, $attrs)
{
$a = array();
foreach ($model as $field) {
foreach (explode(',', $attrs) as $attr) {
$a[$field[$value]] .= $field[$attr]." ";
}
}
return $a;
}
}
use:
<?php echo CHtml::activeDropDownList($model, 'model_id', UHtml::listData(Model::model()->findAll(), 'id', 'attr1,attr2,attr3')); ?>
cheers
include(UHtml.php) [<a href=‘function.include’>function.include</a>]: failed to open stream: No such file or directory
RusAlex
(Pletnev Rusalex)
3
you need to save file ./protected/components/UHtml.php
and then include it via your config
'import'=>array(
'application.models.*',
'application.components.*',
),
Thanks RusAlex… that problem solved… But that $a[$field[$value]] .= $field[$attr]." "; has some offset issue … undefined offset…
Kazio ,
we need to rewrite that code to
public static function listName($model, $value, $attrs)
{
$a = array();
foreach ($model as $field)
{
$a[$field[$value]]=NULL;
foreach (explode(',', $attrs) as $attr)
{
$a[$field[$value]] .= $field[$attr]." ";
}
}
return $a;
}
Declare $a[$field[$value]]=NULL;
Otherwise there is a undefined offset problem
RusAlex, I solved that issue.
and we can solve this multiple attribute issue with CHtml::listData , By writing a function in the model
In Model
public function getJoin()
{
return $this->first_name . ' ' . $this->last_name;
}
and in view call
CHtml::listData(Model::model()->findAll(), 'id', 'Join')
jhmilan
(Jhmilan)
8
Elegant and useful, thank so much.