2013-07-19 32 views
0

我是新Yii中我要显示在顶部CGridView Yii中新插入的项,但不知道它是如何可能的新条目?cgridview显示在顶部警予

public function search() 
    { 
     $criteria=new CDbCriteria; 
     $criteria->alias = "jb"; 
     $criteria->compare('title', $this->title, true); 
     $criteria->compare('notes', $this->notes, true); 
     $criteria->compare('createdon', $this->createdon, true); 
     $criteria->compare('expirydate', $this->expirydate, true); 
     $criteria->join= 'INNER JOIN company co ON (co.companyid=jb.companyid)'; 
     return new CActiveDataProvider(get_class($this), array(
       'criteria' => $criteria, 
     )); 
+0

任何机构帮助PLZ? – user2598211

+0

你尝试在cgridview中排序数据? – Ninad

回答

0

为什么不使用关系进行连接?

$criteria=new CDbCriteria; 
    $criteria->alias = "jb"; 
    $criteria->compare('title', $this->title, true); 
    $criteria->compare('notes', $this->notes, true); 
    $criteria->compare('createdon', $this->createdon, true); 
    $criteria->compare('expirydate', $this->expirydate, true); 
    $criteria->with('company'); 
    $criteria->together=>true; 

    return new CActiveDataProvider(get_class($this), array(
      'criteria' => $criteria, 
    )); 

,然后defaultScope为JB模型

public function defaultScope() 
{ 
    $alias = $this->getTableAlias(false,false); 
    return array(
     'order'=>"`$alias`.`id` DESC", 
    ); 
}