Yii Framework Forum: Problem with CGridView columns when changing data provider - Yii Framework Forum

Jump to content

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

Problem with CGridView columns when changing data provider Rate Topic: -----

#1 User is offline   Trejder 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,197
  • Joined: 06-October 10
  • Location:Southern Poland

Posted 26 January 2011 - 08:18 AM

Hi there,

How can I get actual content of a cell to use it to customise CLinkColumn or to make CButtonColumn work with non-model data providers in CGridView?

I have a controller and view using CGridView along with CActiveDataProvider and it works perfectly. I then copied view code do another view (and controller) and the only thing, I changed was to switch data provider from CActiveDataProvider (Active Record) to CSqlDataProvider (pure SQL query).

The first thing I noticed was "Trying to get property of non-object" in the line of code declaring CButtonColumn:

array
(
    	'class'=>'CButtonColumn',
    	'template'=>'{view}'
)

If I'm not mistaken, this is because I'm using CSqlDataProvider and CButtonColumn seems to be looking for some model property, right? Then the question is how to use CButtonColumn, if not using model-related data provider?

Another problem is with CLinkColumn, which I'm trying to customize with its own contents, for example like that:

array
(
    	'class'=>'CLinkColumn',
    	'labelExpression'=>'$data->UDAT',
    	'url'=>$url,
    	'htmlOptions'=>array('title'=>$title),
),

But this also dies with exactly the same error ("Trying to get property of non-object" in yii\base\CComponent.php(616) with eval()'d code(1)), which is also OK if I'm not mistaken, as CLinkColumn.labelExpression says that $data can be only used when data provider is a model.

So, second question is, that if this piece of code works:

'UDAT:text:Date',

for declaring simple CDataColumn, then how be able to use CLinkColumn in the same context, that is to have cell contents put into label or labelExpression and value of another cell (another column of current data row) - i.e. ID - to be put into url or urlExpression?
Proud Cookbook author, though still learning powerful Yii! :] See my generic profile for more information. Cheers!
0

#2 User is offline   oxigen 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 30
  • Joined: 05-February 09

Posted 28 January 2011 - 06:28 AM

When you use CSqlDataProvider, return $data is array therefore
Change: $data->UDAT
to : $data['UDAT']
2

#3 User is offline   Trejder 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,197
  • Joined: 06-October 10
  • Location:Southern Poland

Posted 29 January 2011 - 10:29 AM

Thanks a lot, that explains much and solves problem of using $data in column that is inside CGridView, which is using CSqlDataProvider.

However, there's still an open question, how to use CButtonColumn in case like that? Am I missing something or in current Yii implementation CButtonColumn can't be used with CGridView that is using CSqlDataProvider as data source?
Proud Cookbook author, though still learning powerful Yii! :] See my generic profile for more information. Cheers!
0

#4 User is offline   Amy 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 22
  • Joined: 04-February 13

Posted 22 March 2013 - 12:39 PM

Quote

When you use CSqlDataProvider, return $data is array therefore
Change: $data->UDAT
to : $data['UDAT']


Just a reminder that you have to escape your quote marks since they're inside another quote. So when you use CSqlDataProvider or CArrayDataProvider this would be the syntax:

$data[\'UDAT\']
1

#5 User is offline   KonApaz 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,323
  • Joined: 21-February 11
  • Location:Greece

Posted 18 March 2014 - 11:27 AM

Because I had questions too about it I wrote a wiki that explains a lot of things about CSqlDataProvider and use in CGridview

http://www.yiiframew...r-in-cgridview/
Yii is the best php framework in the world!
find our demo Yii extension on www.webkit.gr
Is it post useful? please v++ ;)
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