Yii Framework Forum: Need Help With Last Record - Yii Framework Forum

Jump to content

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

Need Help With Last Record Rate Topic: -----

#1 User is offline   9565598 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 21-January 13

Posted 21 January 2013 - 02:44 AM

Hello every1! Have a problem! Need show clients in gridView with their last activity.
    public function relations()
    {
        return array(
            'clientsInfoProgram'  => array(self::HAS_MANY, 'ClientsInfoProgram', 'client_id', 'order'=>'clientsInfoProgram.date_begin DESC'),
 );
    }


GridView
  
        array(
            'name' => 'clientsInfoProgram.date_begin',
            'value' => 'CModelHelper::getObjLastValue($data->clientsInfoProgram, "date_begin")',
            'filterHtmlOptions' => array('class' => 'FilterDate','style'=>'width:95px'),
            'filter' => CHtml::textField(get_class($model).'[clients_date_begin]', $model->clients_date_begin),
        ),


CModelHelper::getObjLastValue
        public static function getObjLastValue($arr, $key){
            if(count($arr)){
                foreach($arr as $i => $val){
                    if(!empty($val->$key)){
                        $rval = $val->$key;
                        break;
                    }
                }
                return $rval;
            }
        }


But this select first activity record! :-[
0

#2 User is offline   9565598 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 21-January 13

Posted 22 January 2013 - 03:15 AM

Yes i get it
        
$criteria=new CDbCriteria;
   
        $criteria->with = array(
            'clientsInfoProgram' => array('select'=> 'MAX(clientsInfoProgram.date_begin) as date_begin'),
        );

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