kitty10
(Martde)
1
My code is :
<?php echo CHtml::activeDropDownList($model,‘STUDENTE_MATRICOLA’,CHtml::listData(anagrafe::model()->findAll(array(‘order’=>‘COGNOME’)),‘ANAGRA_ID’,‘COGNOME’));?>
I would like to display two fields in the dropdownlist the name and surname not only the surname(‘order’=>‘COGNOME’).How can I do?
mdomba
(Maurizio Domba Cerin)
2
phpdevmd
(Phpdevmd)
3
Here is an alternative to the excellent method above:
Use anagrafe Model. example:
private $_allStudenteMatricolaValues;
public function getAllStudenteMatricolaValues()
{
if($this->_allStudenteMatricolaValues===null)
{
$rows=array();
$criteria=new CDbCriteria(array(
'select'=>"`ANAGRA_ID`,`COGNOME`,`COGNOME2`",
'order'=>"`COGNOME`",
));
foreach(anagrafe::model()->findAll($criteria) as $model)
$rows[$model->ANAGRA_ID]=$model->COGNOME.' '.$model->COGNOME2;
$this->_allStudenteMatricolValues=$rows;
}
return $this->_allStudenteMatricolaValues;
}
CHtml::activeDropDownList($model,'STUDENTE_MATRICOLA',anagrafe::model()->allStudenteMatricolaValues);?>
or if $model is instance of anagrafe use this instead:
CHtml::activeDropDownList($model,'STUDENTE_MATRICOLA',$model->allStudenteMatricolaValues);?>
kitty10
(Martde)
4
My code in the model ANAGRAFE is:
private $_allStudenteMatricolaValues;
public function getAllStudenteMatricolaValues()
{
if($this->$_allStudenteMatricolaValues===null)
{
$rows=array();
$criteria=new CDbCriteria(array(
'select'=>"ANAGRA_ID,COGNOME,NOME",
'order'=>"COGNOME",
));
foreach(anagrafe::model()->findAll($criteria) as $model)
$rows[$model->ANAGRA_ID]=$model->COGNOME.' '.$model->NOME;
$this->_allStudenteMatricolValues=$rows;
}
return $this->$_allStudenteMatricolaValues;
}
In the view is:
<?php echo CHtml::activeDropDownList($model,‘STUDENTE_MATRICOLA’,anagrafe::model()->allStudenteMatricolaValues);?>
But this code don’t work…
the error is
Property "anagrafe." is not defined.
mdomba
(Maurizio Domba Cerin)
5
if your model is ANAGRAFE than use that not anagrafe
P.S. Why you don’t use the [code ] directive… without it your code is difficult to read 
kitty10
(Martde)
6
Don’t understand your reply
Not a problem case sensitive