Problematic Linkbutton in gridview

I need to add a LinkColumn to the GridView used to display the results of the searches. The code generated by gii is the following:




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

	'id'=>'obra-grid',

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

	'filter'=>$model,

	'columns'=>array(

		'idObra',

		'idPintor',

		'idEstilo',

		'nombreObra',

		'fechaObra',

		'anchoObra',

		array(

			'class'=>'CButtonColumn',

		),

	),

));



I started to modify this code but I don’t know how to get the file name that is composed by two fields of the item showed in the same record of the gridview.




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

	'id'=>'obra-grid',

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

	'filter'=>$model,

	'columns'=>array(

		array(

			'class'=>'CLinkColumn',

			'imageUrl'=>'uploads/thumbnails/'.[[[FILE NAME HERE]]],

			'url'=>'uploads/thumbnails/'. [[[FILE NAME HERE]]],

		),

		'idObra',

		'idPintor',

		'idEstilo',

		'nombreObra',

		'fechaObra',

		'anchoObra',

		array(

			'class'=>'CButtonColumn',

		),

	),

));



Finally I have another question: What I should do in order to show only one o two of the buttons that appear in the ButtonColumn?

Hi, to your first question:

http://www.yiiframework.com/wiki/167/understanding-virtual-attributes-and-get-set-methods

to your second:

http://www.yiiframework.com/doc/api/1.1/CButtonColumn/#template-detail

Firstly, thanks for your answer. My second problem is indeed solved but the first one not. I was reading the article you suggested me and I see that I can create, for example, a column displaying the image url but the problem is create a CLinkColumn that shows the images. The problem is how I tell to that LinkColumn that for each cell of the column the image Url must be obtained from the model corresponding to the record?

You can create a virtual attribute Url on the model. :) jsut define a public function getUrl() on the model as specified in the article.




array(

'class'=>'CButtonColumn',

'template'=>'{butonone}{buttontwo}',

'buttons'=>array(

//buuton id or name

'butonone' => 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

) ,

'buttontwo' => 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

) 

)


),



Yes I did it but the problem is how I accsess to that function in the expression that must be defined for imageUrl property of the LinkButton.

I understand this. If you see the code in my first post you will see something similar but using a Linkcolumn instead a ButtonColumn. The problem, using your example code, i that i don´t know how to define the php expression for url or for image url because these properties are diferent for each record, depending on some fields of that record. I don´t know how tell to that column that for each cell it has to construct a different url or imageUrl.

you can make expression in function and call in that imageurl property

Well, after trying everything I started to dive into the Yii code and I saw that what I was needing was really impossible. So I wrote a very simple extension and now my needs are fulfilled. Thanks to all of you.

Greetings.

Nearly imposible?


$data->url

did not do the trick for you after creating a getUrl() in the model?

It works for URL, which is an expresion but does not work for imageUrl. I had the same problem.

imageUrl is not an expression, is a simple value evaluated just one time.

As far as I see it’s impossible to use an expression including row data in the imageUrl.