how to get Dynamic Cbuttoncolumns in Cgridview

I’m trying to have a dynamic CButtonColumn in a CGridview :

1st problem

template doesnt seem to accept dynamic value.

in my button…

when I try

	 array(


		'id'=>'action-button',


		'header'=>'action',


		'class'=>'CButtonColumn',


		'template'=>Businesspromo::temptocheck($data["languages"]),

or

		'template'=>Businesspromo::temptocheck($data->languages),

temptocheck return a string base on the content of $data[languages]

error Undefined variable: data

So I tried

	'template'=>'Businesspromo::temptocheck($data["languages"])',

in this case the text ‘Businesspromo::temptocheck($data[“languages”])’ is display in the content of the column :frowning:

Any solution to have buttons based on the content of the line?

You can not use a PHP expression for "template" attribute of CButtonColumn. So you may not change the template row by row.

According to the reference manual, the attributes that accept a PHP expression are:

  • cssClassExpression

  • deleteButtonUrl

  • updateButtonUrl

  • viewButtonUrl

And in the ‘buttons’ property, you can use a PHP expression for

  • url

  • visible

CButtonColumn

So, it’s not tested, but what about this:




	array(

		'class' => 'CButtonColumn',

		'buttons'=>array(

			'edit' => array(

				'visible'=>'Businesspromo::editVisible($data["languages"])',

			),

			'view' => array(

				'visible'=>'Businesspromo::viewVisible($data["languages"])',

			),

		),

	),



I’m not sure the ‘buttons’ attributes take effects on standard ‘edit’, ‘view’ and ‘delete’ buttons.

thanks for the answer.

I think I made maybe a mistake in my explanation.My problem doesnt concern the standard buttons but customized buttons.

i may have a lot of buttons. its based on the languages to be translated on the line.

so, on each line I could have n buttons to translate for the targeted languages.

the targeted language is dynamic.

so, i have the solution to prepare all button, and use the visible attribute to display it… but every time we had a new language… I have to modify the cgridview to add the language as potential button…

or have dynamic buttons…

example :

-the business maybe translated in en, fr, tl, ko ( so 4 potential languages)

  • on very business promo, depending of my business ( the cgrid is on the businesspromo)

  • I add a button to translate in the languages when the translation is not already done…

but for an other business, the targeted languages may be de, ko, ja, it

and so i wanted tto make a function, to create the buttons based on the 2 parameters, and so… be able to transmit some information to template… or even to generate directly an array for the cbutton.

Any way… thank for your help, it maybe the only solution… prepare all buttons , and use just ‘visible’, in waiting to find a better solution.

I see.

I would rather use the standard CDataColumn in your case, not CButtonColumn.

After all, “button” is just a link with an image. It can be rendered using ‘value’ property of CDataColumn with ‘type’ set to ‘raw’.