Editing Admin and Search page

Hi

I have a model named Publised, it’s a checbox model. On my Admin View on Search it displays either 1 or 0, as in 1 being published and 0 not. What I want is to display Yes or No instead of 1 or 0.

So basically I want something




if(model->Published > 0 ){

//show Yes for each row on my Admin page


}else{

//show No for each row on my Admin page

}




I need to know how to access the model text and change it’s output. Would I have to actually change the DB input.

Thanks

try CHtml::activeDropDownList($model, ‘attribute’, array(‘0’=>‘No’, ‘1’=>‘Yes’)); instead of the text field

Thanks for the reply, I tried


<div class="row">

		<?php echo $form->label($model,'Published'); ?>

		<?php 

		echo $form->CHtml::activeDropDownList($model, 'Published', array('0'=>'No', '1'=>'Yes'));		?>

		

	</div>

Inside my _search.php file but I get nothing. Just the title Page but no search items. Everything else disappeared.

Nope. In your case it should be


<div class="row">

		<?php echo $form->label($model,'Published'); ?>

		<?php 

		echo $form->dropDownList($model, 'Published', array('0'=>'No', '1'=>'Yes'));		?>

		

	</div>

Ok I tried that, I get the drop down option if I click on Advance Search but not on the main search page (the widget). I’m using the generic CGridView Search model. It displays 1’s and 0’s still.

Thanks

ok then go ahead and change it in the _search.php view or whatever the search widget uses as a view

I have but I get this error


<?php $this->widget('zii.widgets.grid.CGridView', array(

	'id'=>'eccategory-grid',

	'dataProvider'=>$model->search(),

	'filter'=>$model,

	'columns'=>array(

	 'ID',

 

	

        array(

            'name'=>'Published',

			

            'filter'=>CHtml::dropDownList($model, 'Published',  

                array(

                    '1'=>'Yes',

                    '0'=>'No',

                )

            ),

        ),

		'ParentID',

		'Name',

		'Description',

		

		'CatOrder',

		/*

		'Template',

		'PictureFooterOff',

		'IsConsumer',

		'IsBusiness',

		'NameArabic',

		'DescriptionArabic',

		*/

		array(

			'class'=>'CButtonColumn',

		),

	),

)); ?>



That’s my attempt to put it inside the CGridView.

Thanks again

it should be


'filter'=>CHtml::activeDropDownList......

Yh that’s working but how can I get my 1’s and o’s to become Yes and No. I mean in the DB table they are stored as 1’s and 0’s so that is what the Admin page shows. Your input gave me a nice way to filter but I actually want to display Yes and No.

Right now I got

Published

Dropdownlist

1

1

1

1

0

1

but I want

Published

Dropdownlist

Yes

Yes

Yes

Yes

No

Yes

That was my original intent. Would you know how to go about this?

Thanks

this is managed in the value attribute:


array(

            'name'=>'Published',

            'value'=>'$data->Published==\'0\' ? "No":"Yes"',

            'filter'=>CHtml::activeDropDownList($model, 'Published',  

                array(

                    '1'=>'Yes',

                    '0'=>'No',

                )

            ),

        ),

Brilliant that’s done it. Thanks for all the support mate you’re a star.

Regards