Yii Framework Forum: Admin View Edit/Delete buttons - Yii Framework Forum

Jump to content

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

Admin View Edit/Delete buttons Rate Topic: -----

#1 User is offline   rymonator 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 124
  • Joined: 02-December 10

Posted 08 December 2010 - 04:35 PM

Hello, my goal is to create the same style list that is on the admin view on the index page, which I have done. Basically, I got rid of the admin (manage) page and am just using an index page. However, what I want to do is have a version that has the edit/delete buttons in the right hand column and one that doesn't. If you are not logged in, you can see the list of items and view each one in full by clicking the magnifying glass. If you are logged in, you can also delete or edit each item. How would I go about doing this? Here is the code that creates the list:

?php $this->widget('zii.widgets.grid.CGridView', array(
	'id'=>'stories-grid',
	'dataProvider'=>$model->search(),
	'filter'=>$model,
	'columns'=>array(
		'attr1',
		'attr2',
		'attr3',
		array(
			'class'=>'CButtonColumn',
		),
	),
)); ?>


I can of course get rid of the array('class'=>'...'), but that also gets rid of the magnifying glass. I also don't really know how to check if a user is logged in. Sorry, I'm a Yii noob.
0

#2 User is offline   awesomejuice 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 35
  • Joined: 22-July 10

Posted 08 December 2010 - 05:50 PM

You should use the 'visible' property of CGridColumn. You can use Yii::app()->user->isGuest to check that your user is logged in. So:

array(
   'class'   => 'CButtonColumn',
   'visible' => Yii::app()->user->isGuest,
),

0

#3 User is offline   Maurizio Domba Cerin 

  • Yii - Yesss It Is !!!
  • Yii
  • Group: Yii Dev Team
  • Posts: 4,370
  • Joined: 12-October 09
  • Location:Croatia

Posted 09 December 2010 - 03:04 AM

The visible property is evaluated for every row so it's good to use if you need to display/hide "data" from row to row...

Check this post it could give you a good idea - http://www.yiiframew...dpost__p__46410
Find more about me.... btw. Do you know your WAN IP?
0

#4 User is offline   rymonator 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 124
  • Joined: 02-December 10

Posted 09 December 2010 - 09:12 AM

Thanks guys, this helps, but I'm still not sure how to exclude certain buttons from the cbuttonview in the case that a user is logged in vs. the user is an admin.

So here is there some option to do this?

'columns'=>array(
		'x','y,'z',
		array(
			'class'=>'CButtonColumn', 
			'visible' => !Yii::app()->user->isGuest, //with this option only a logged in user sees the buttons
		),


So 1.) Is there a visibility option (or some other isXXXX method) that checks if a user is an admin as opposed to just logged in? and 2.) is there an option I can use in the CButtonColumn array that excludes certain buttons (e.g. delete)? THANKS!
0

#5 User is offline   Maurizio Domba Cerin 

  • Yii - Yesss It Is !!!
  • Yii
  • Group: Yii Dev Team
  • Posts: 4,370
  • Joined: 12-October 09
  • Location:Croatia

Posted 09 December 2010 - 09:20 AM

How do you give a user the ADMIN status... tha you should check...

As for the buttons there is a "visible" property for every button - http://www.yiiframew...#buttons-detail

but as I wrote above it would be better to do something like

if admin
   show all buttons
else
   show only view button

Find more about me.... btw. Do you know your WAN IP?
0

#6 User is offline   Thirumalai 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 58
  • Joined: 20-November 10

Posted 09 December 2010 - 09:24 AM

View Postrymonator, on 09 December 2010 - 09:12 AM, said:

Thanks guys, this helps, but I'm still not sure how to exclude certain buttons from the cbuttonview in the case that a user is logged in vs. the user is an admin.

So here is there some option to do this?

'columns'=>array(
		'x','y,'z',
		array(
			'class'=>'CButtonColumn', 
			'visible' => !Yii::app()->user->isGuest, //with this option only a logged in user sees the buttons
		),


So 1.) Is there a visibility option (or some other isXXXX method) that checks if a user is an admin as opposed to just logged in? and 2.) is there an option I can use in the CButtonColumn array that excludes certain buttons (e.g. delete)? THANKS!

array(
			'class'=>'myButtonColumn',
                        'deleteButtonVisible'=>'false',
		)

0

#7 User is offline   Maurizio Domba Cerin 

  • Yii - Yesss It Is !!!
  • Yii
  • Group: Yii Dev Team
  • Posts: 4,370
  • Joined: 12-October 09
  • Location:Croatia

Posted 09 December 2010 - 09:36 AM

@Thirumalai

Note that deleteButtonVisible does not exist in Yii... myButtonColumn is an extension that was needed before "visible" was implemented in Yii...

Instead now in Yii this can be used
'buttons'=>array(
   'delete'=>array(
   	'visible'=>false
   )
)

Find more about me.... btw. Do you know your WAN IP?
0

#8 User is offline   rymonator 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 124
  • Joined: 02-December 10

Posted 09 December 2010 - 09:47 AM

Thanks but I'm getting the error call_user_func_array() [<a href='function.call-user-func-array'>function.call-user-func-array</a>]: First argument is expected to be a valid callback, '' was given with the following:


 $this->widget('zii.widgets.grid.CGridView', array(
	'id'=>'stories-grid',
	'dataProvider'=>$model->search(),
	'filter'=>$model,
	'columns'=>array(
		'x','y','z',
		array(
			'class'=>'CButtonColumn',
			'buttons' => array(
				'delete' => array(
					'visible' => false
				)
			)
		)
	),
)); 

0

#9 User is offline   Maurizio Domba Cerin 

  • Yii - Yesss It Is !!!
  • Yii
  • Group: Yii Dev Team
  • Posts: 4,370
  • Joined: 12-October 09
  • Location:Croatia

Posted 09 December 2010 - 09:57 AM

Just checked.. 'visible' should be an expression that is evaluated... so you can use 'false'... or any expression that returns true or false...
Find more about me.... btw. Do you know your WAN IP?
0

#10 User is offline   rymonator 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 124
  • Joined: 02-December 10

Posted 09 December 2010 - 10:02 AM

View Postmdomba, on 09 December 2010 - 09:57 AM, said:

Just checked.. 'visible' should be an expression that is evaluated... so you can use 'false'... or any expression that returns true or false...


THANKS it worked!
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