Display column name


I would like to display some of column (table field) name in view part.

Can you suggest me any idea, on it?

Thank you for your help :)

I dont really get what you want, but here some suggestions

to get models metadata ( info about table) you could use


to get info about its columns


but I think what you are looking for is


try to print_r its content and see if it is what you are looking for

Thank Gustavo for suggestion.

I will display what I have done in view part (index.php)

foreach(Yii::app()->db->schema->getTable('tbl_contactinfo')->columns as $key=>$val) {

 		echo $form->label($model,$key);

		echo $form->hiddenField($modelContactInfo,$key);

		echo CHtml::dropDownList('privacyStatus','', $model->getStatusOptions(),


		      	'ajax' => array(

				'type'=>'POST', //request type

				'url'=>CController::createUrl('status'), //url to call.				




It displays all the columns of the particular table ‘say tbl_contactinfo’. But my requirement is to get just few columns instead of all.

which ones?

I didn’t get what you mean Which one?

What do you mean by "a few columns not all " ??

I dont actually get


support the table ‘tbl_contactinfo’ has 6 fields[color=#008800][font=monospace][size=2] [/size][/font][/color]The above code will display all the columns. I just need to display only 3 columns out of 6.


foreach(array_slice($columns,0,3) as $columns){



that will solve it

or you could use a counter and break the loop, like


foreach(Yii::app()->db->schema->getTable('tbl_contactinfo')->columns as $columns){






But the populate of columns are in random. The column display can be : column1, column3, column5.

It actually is ordered exactly like the table, here I’m using Mysql

Do you want in order or which ones do you want ? 3 random or 3 first ?

if 3 random fields use

foreach(shuffle($column) as $columns){



Gustavo, thank you for your support. cheers :)

Glad I could help