Yii Framework Forum: Editing Admin and Search page - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Editing Admin and Search page To display default text on search page Rate Topic: -----

#1 User is offline   ItsYii 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 104
  • Joined: 24-January 12

Posted 19 June 2012 - 04:33 AM

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
0

#2 User is offline   bettor 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 726
  • Joined: 02-February 09

Posted 19 June 2012 - 05:25 AM

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

#3 User is offline   ItsYii 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 104
  • Joined: 24-January 12

Posted 19 June 2012 - 07:20 AM

View Postbettor, on 19 June 2012 - 05:25 AM, said:

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.
0

#4 User is offline   bettor 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 726
  • Joined: 02-February 09

Posted 19 June 2012 - 07:24 AM

View PostItsYii, on 19 June 2012 - 07:20 AM, said:

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>

1

#5 User is offline   ItsYii 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 104
  • Joined: 24-January 12

Posted 19 June 2012 - 08:17 AM

View Postbettor, on 19 June 2012 - 07:24 AM, said:

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
0

#6 User is offline   bettor 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 726
  • Joined: 02-February 09

Posted 19 June 2012 - 08:37 AM

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

#7 User is offline   ItsYii 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 104
  • Joined: 24-January 12

Posted 20 June 2012 - 06:33 AM

View Postbettor, on 19 June 2012 - 08:37 AM, said:

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

Quote

Object of class ECCategory could not be converted to string


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

#8 User is offline   bettor 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 726
  • Joined: 02-February 09

Posted 20 June 2012 - 06:54 AM

it should be
'filter'=>CHtml::activeDropDownList......

1

#9 User is offline   ItsYii 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 104
  • Joined: 24-January 12

Posted 20 June 2012 - 08:06 AM

View Postbettor, on 20 June 2012 - 06:54 AM, said:

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
0

#10 User is offline   bettor 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 726
  • Joined: 02-February 09

Posted 20 June 2012 - 08:34 AM

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',
                )
            ),
        ),

1

#11 User is offline   ItsYii 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 104
  • Joined: 24-January 12

Posted 20 June 2012 - 09:03 AM

View Postbettor, on 20 June 2012 - 08:34 AM, said:

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
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users