Yii Framework Forum: url/urlExpression property of the CLinkColumn - Yii Framework Forum

Jump to content

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

url/urlExpression property of the CLinkColumn Rate Topic: -----

#1 User is offline   mocapapa 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 424
  • Joined: 04-January 09
  • Location:Tokyo, JAPAN

Posted 26 January 2010 - 04:11 AM

I am making use of CGridview widget with the 'columns' property being 'CLinkColumn', because I would like to embed a link to the other table (view).What I would like to do is the following.
    'columns'=>array(
          :
        array(
            'class'=>'CLinkColumn',
                'labelExpression'=>'$data->code', // this line is fine!
                'url'=>array(
                    'member/admin',
                    'code'=>'$data->code', // this line is NG!
                ),
          :

It is not working because 'url' parameter does not recognize '$data' keyword, though I would like to link this item to 'actionAdmin' of 'MemberController' having dynamic 'code' parameter.I actually did following but failed because urlExpression does not recognize array structure on the other hand.
    'columns'=>array(
          :
        array(
            'class'=>'CLinkColumn',
                'labelExpression'=>'$data->code', // this line is fine!
                'urlExpression'=>array( // this line is NG!
                    'member/admin',
                    'code'=>'$data->code',
                ),
          :

Is there any good way to do it?
// I have found an ugly WA though...
0

#2 User is offline   got 2 doodle 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 247
  • Joined: 12-December 08
  • Location:Beautiful Nova Scotia, Canada

Posted 26 January 2010 - 05:13 PM

Does this help?
array( 'class'=>'CLinkColumn',
                        'header'=>'Last Name',
                        'labelExpression'=>'$data->ParticipantLastname',
                        'urlExpression'=>'Yii::app()->createUrl("participant/list",array("lastname"=>$data->ParticipantLastname))',
                        'linkHtmlOptions'=>array('title'=>'See all entries with this last name'))


doodle
Check out myYii powered website
2

#3 User is offline   mocapapa 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 424
  • Joined: 04-January 09
  • Location:Tokyo, JAPAN

Posted 26 January 2010 - 07:56 PM

Thanks doodle,

View Postgot 2 doodle, on 26 January 2010 - 05:13 PM, said:

Does this help?
array( 'class'=>'CLinkColumn',
                        'header'=>'Last Name',
                        'labelExpression'=>'$data->ParticipantLastname',
                        'urlExpression'=>'Yii::app()->createUrl("participant/list",array("lastname"=>$data->ParticipantLastname))',
                        'linkHtmlOptions'=>array('title'=>'See all entries with this last name'))


doodle

That works fine!
0

#4 User is offline   sn0rcha 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 28
  • Joined: 22-June 09

Posted 09 March 2010 - 07:23 PM

View Postmocapapa, on 26 January 2010 - 07:56 PM, said:

Thanks doodle,


That works fine!


I can't seem to get the 'linkHtmlOptions' to register. I'm using the latest version of Yii with the following code;

 array( 'class'=>'CLinkColumn',
                        'header'=>'Print',
                        'labelExpression'=>'"Print Order #$data->products_orders_id"',
                        'urlExpression'=>'Yii::app()->createUrl("productsOrders/print",array("id"=>$data->products_orders_id))',
                        'linkHtmlOptions'=>array('target'=>'_blank')),  


Everything works except the 'linkHtmlOptions' which seem to be getting ignored... Any ideas?
0

#5 User is offline   windsor 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 60
  • Joined: 04-October 11
  • Location:Tampa, FL

Posted 17 November 2011 - 06:39 PM

View Postsn0rcha, on 09 March 2010 - 07:23 PM, said:

I can't seem to get the 'linkHtmlOptions' to register. I'm using the latest version of Yii with the following code;

 array( 'class'=>'CLinkColumn',
                        'header'=>'Print',
                        'labelExpression'=>'"Print Order #$data->products_orders_id"',
                        'urlExpression'=>'Yii::app()->createUrl("productsOrders/print",array("id"=>$data->products_orders_id))',
                        'linkHtmlOptions'=>array('target'=>'_blank')),  


Everything works except the 'linkHtmlOptions' which seem to be getting ignored... Any ideas?


Try this...


'linkHtmlOptions'=>array('target'=>'"_blank"'),



+1 me if it helps! :rolleyes:
1

#6 User is offline   Amy 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 19
  • Joined: 04-February 13

Posted 22 March 2013 - 12:35 PM

I was using CArrayDataProvider instead of CActiveDataProvider so I couldn't use object notation to reference the data I wanted. I struggled trying to get the syntax correct.

In case it helps someone else, here's the change. Instead of
'labelExpression'=>'$data->ParticipantLastname',

you change it to array referencing AND escape the quotes:
'labelExpression'=>'$data[\'ParticipantLastname\']',


BTW - it also took me a while to understand that $row and $data are magically available. $row is the current row number, $data is an array of the data for that row.

HTH someone.
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