Dropdownlist

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?

Take a look here: http://www.yiiframework.com/forum/index.php?/topic/8150-multiple-attributes-in-chtmllistdata/page__hl__dropdownlist__fromsearch__1

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);?>

My code in the model ANAGRAFE is:

private $_allStudenteMatricolaValues;

public function getAllStudenteMatricolaValues()

{


    if(&#036;this-&gt;&#036;_allStudenteMatricolaValues===null)


    {


            &#036;rows=array();


            &#036;criteria=new CDbCriteria(array(


                    'select'=&gt;&quot;ANAGRA_ID,COGNOME,NOME&quot;,


                    'order'=&gt;&quot;COGNOME&quot;,


            ));


            foreach(anagrafe::model()-&gt;findAll(&#036;criteria) as &#036;model)


                &#036;rows[&#036;model-&gt;ANAGRA_ID]=&#036;model-&gt;COGNOME.' '.&#036;model-&gt;NOME;


            &#036;this-&gt;_allStudenteMatricolValues=&#036;rows;


    }


    return &#036;this-&gt;&#036;_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.

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 ???

Don’t understand your reply

Not a problem case sensitive