how to echo an array in _view.php eg: 0 = a, 1 = b

Hi i’m doing the dropdownlist option functions in model.php by




const CAT_stuff1 = 0;

const CAT_stuff3 = 2;


function getCATOptions()

{

    return array(

       self::CAT_stuff1 => 'the stuff'

       self::CAT_stuff1 => 'the cool stuff'

    )

}



and in _form.php




    echo $form->dropDownList($model, 'category', $model->getCATOptions());



now how do i output the name(stuff, cool stuff) instead of 0, 1 to the _view.php on this line




     echo CHtml::encode($data->category);



thancks

http://www.yiiframework.com/wiki/276/simple-authorization-system/#hh3


$cat_options = $data->getCATOptions();

echo CHtml::encode($cat_options[$data->category]);

Thanks Aruna!! perfect answer. thats exactly what i needed

Hey Aruna, i ran into the second problem, i read through the simple authorisation from Gustavo, and want to add the same thing to the CGridView in the admin.php

i replaced this line in the array


'category',

with another array


   

                array(

                        'category' => '$data->getCatOption[$data->category]',

                ),



and i get this alert

Property "CDataColumn.category" is not defined.

where to define this?


// I suggest you below way.

// In your model define as below


const CAT_stuff1 = 0;

const CAT_stuff3 = 2;


public $catOptions = array(self::CAT_stuff1=>'the stuff',

						   self::CAT_stuff3=>'the cool stuff');

						   

// in _view.php


echo CHtml::encode($data->catOptions[$data->category]);


// in admin.php


array('name'=>'category', 

	  'value'=>'$data->catOptions[$data->category]'),