Yii Framework Forum: Using Two $Data In Cgridview Value - Yii Framework Forum

Jump to content

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

Using Two $Data In Cgridview Value Rate Topic: -----

#1 User is offline   gerilla 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 14
  • Joined: 22-July 13

Posted 18 October 2013 - 09:42 AM

hi,
i create a relationship with customer and income tables. it works ok. i can show name values at income cgridview:

array('name'=>'customer','value'=>'$data->customer->name',),


but i need show name and surname values in a single column in income cgridview.

array('name'=>'customer','value'=>'$data->customer->name $data->customer->surname',),


this doesnt work.

any help?
0

#2 User is offline   Keith 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 1,601
  • Joined: 04-March 10
  • Location:UK

Posted 18 October 2013 - 10:37 AM

array('name'=>'customer','value'=>'$data->customer->name . " " . $data->customer->surname',),

0

#3 Guest_Interboy_*

  • Group: Guests

Posted 18 October 2013 - 12:43 PM

View Postgerilla, on 18 October 2013 - 09:42 AM, said:

hi,
i create a relationship with customer and income tables. it works ok. i can show name values at income cgridview:

array('name'=>'customer','value'=>'$data->customer->name',),


but i need show name and surname values in a single column in income cgridview.

array('name'=>'customer','value'=>'$data->customer->name $data->customer->surname',),


this doesnt work.

any help?



Try create a new function in model.
public function getFullname(){
return $this->customer->name . ' ' . $data->this->surname;
}


In your gridview:

array('name'=>'customer','value'=>'$data->fullname',),

0

#4 User is offline   chandran 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 494
  • Joined: 08-October 12
  • Location:Austria

Posted 18 October 2013 - 02:27 PM

Hi,


You can access the controller in this way inside grid


$this->grid->controller

Write this method in controller

public function getFullname(){ return $this->customer->name . ' ' . $this->customer->surname; }
In view u can access

array('name'=>'customer','value'=>'$this->grid->controller->getFullname()',),
Thanks
chandran nepolean

My own extension:
http://www.yiiframew...sion/ejqueryte/

My wiki
http://www.yiiframew...checkboxcolumn/

If it work dont hesitate to click +1 button
0

#5 User is offline   gerilla 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 14
  • Joined: 22-July 13

Posted 19 October 2013 - 03:54 AM

View PostKeith, on 18 October 2013 - 10:37 AM, said:

array('name'=>'customer','value'=>'$data->customer->name . " " . $data->customer->surname',),



thanks it works. thanks for other replies, too.


but i have another trouble now. when i enter name in filter input it finds customer, but when i enter surname in filter inputbox at cgridview, it cant find customer, cos it searches at only name in search criteria in model file:
$criteria->compare('customer.name',$this->mid);


how can i add name with surname to search criteria?
0

#6 User is offline   gerilla 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 14
  • Joined: 22-July 13

Posted 19 October 2013 - 04:13 AM

ok i made it. i add this code in model search func. and it works:

$criteria->compare('customer.name',$this->mid);
$criteria->addSearchCondition('customer.surname',$this->mid,'true','OR');

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