Yii Framework Forum: CButtonColumn $data and $row in button=>options clause, not ony in url and visible - Yii Framework Forum

Jump to content

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

CButtonColumn $data and $row in button=>options clause, not ony in url and visible Rate Topic: -----

#1 User is offline   vitman 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 14
  • Joined: 09-April 12

Posted 06 June 2012 - 07:30 AM

'buttonID' => array(
    'label'=>'...',     // text label of the button
    'url'=>'...',       // a PHP expression for generating the URL of the button
    'imageUrl'=>'...',  // image URL of the button. If not set or false, a text link is used
    'options'=>array(...), // HTML options for the button tag
    'click'=>'...',     // a JS function to be invoked when the button is clicked
    'visible'=>'...',   // a PHP expression for determining whether the button is visible
)

In the PHP expression for the 'url' option and/or 'visible' option, the variable $row refers to the current row number (zero-based), and $data refers to the data model for the row. 

quote from docs
Is it will not be useful have ability to do something like that
'some_button' => array(
       'click' =>  "call_my_func($data['ID'])"));

0

#2 User is offline   Luke Jurgs 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 162
  • Joined: 16-October 11
  • Location:Australia

Posted 08 June 2012 - 01:14 AM

I've wanted this a few times, I even wrote an extension to make it possible to do evaluated CHtml::ajaxLink cells.

I think a better way to go (IMHO) is to add an "as expression" option, then you could do this:

//php 5.3
'label'=>'...',     // text label of the button
'asExpression'=>function($data, $row) {
  return array(
    'url' => $data->id,
    'imageUrl' => $data->image,
  )
}
//php 5.x
'label'=>'...',     // text label of the button
'asExpression'=> "array(
    'url' => \$data->id,
    'imageUrl' => \$data->image,
  )",


The renderCell method could just merge this array back in if you've set anything.
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