Nicolas400
(Nicolas Machado)
November 18, 2011, 3:43am
1
Hi,I want to concatenate attributes in a CHtml::listData
$recs = Socio::model()->findAll(array('order'=>'id')); //el array genera un CDBCriteria()
$data = CHtml::listData($recs,'id','apellidoynombre');
I’m using this to populate a DropDown List
Work fine, but I want to see the internar ID along with the name.
I try:
$data = CHtml::listData($recs,‘id’,‘apellidoynombre.id’);
$data = CHtml::listData($recs,‘id’,‘apellidoynombre+id’);
But nothing works
Any idea ? any tip ??
I want to show a DropDown list with somethin like
Where (1) and (2) is an internal id.
Best Regards.
kokomo
(Mwerlberger85)
November 18, 2011, 7:40am
2
I try:
$data = CHtml::listData($recs,‘id’,‘apellidoynombre.id’);
$data = CHtml::listData($recs,‘id’,‘apellidoynombre+id’);
Try
$data = CHtml::listData($recs,'id','apellidoynombre'.id);
// or
$data = CHtml::listData($recs,'id','apellidoynombre'.' '.id);
Nicolas400
(Nicolas Machado)
November 18, 2011, 12:17pm
3
kokomo:
Try
$data = CHtml::listData($recs,'id','apellidoynombre'.id);
// or
$data = CHtml::listData($recs,'id','apellidoynombre'.' '.id);
No luck, kokomo …
eventhough, I can’t figure out how the string is concatenated in Value function:
public static function value($model,$attribute,$defaultValue=null)
{
foreach(explode('.',$attribute) as $name)
{
if(is_object($model))
$model=$model->$name;
else if(is_array($model) && isset($model[$name]))
$model=$model[$name];
else
return $defaultValue;
}
return $model;
}
Maybe I should use for this case, some SQL statement directly.
Regards
kokomo
(Mwerlberger85)
November 18, 2011, 1:36pm
4
Hmmm, I was pretty sure that one of my above solutions work
Another aproach would be to alter the $data variable which is only an array in a specific form I think.
Do a
CVarDumper::dump($data);
to see the array structure and then manipulate that array values to your needs. Write a function for this task so you can reuse it.
The SQL approach you mentioned should also work.
adinugro
(Adinugro)
November 18, 2011, 11:05pm
5
Hi,
What I am usually do and work is like this
$data = CHtml::listData($recs,'id','idApellidoynombre');
and then on your model add this method
public function getIdApellidoynombre() {
return 'Customer ' . $this->apellidoynombre . ' (' . $this->id . ')'; // or whatever format you want to display
}
lida
(Adilshahzad82)
May 22, 2013, 7:50am
6
Daniel:
Hi,
What I am usually do and work is like this
$data = CHtml::listData($recs,'id','idApellidoynombre');
and then on your model add this method
public function getIdApellidoynombre() {
return 'Customer ' . $this->apellidoynombre . ' (' . $this->id . ')'; // or whatever format you want to display
}
Hi Daniel,
I’m also looking for string/column concatenation but in all the forums it’s suggested to create the function inside the Model which can’t satisfy me.
For example: You have 4 columns id, first_name, last_name, father_name & you need to concatenate first_name with the last_name and in another point you need last_name with father_name. So you’ll be keep creating different functions to concatenate the columns, I hope you follow me?
Thanks,
Adil