0

我是 Yii 的新手 我想在 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,
        ));
4

1 回答 1

0

Why don't you use relations for your join?

$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,
    ));

and then defaultScope for jb model

public function defaultScope()
{
    $alias = $this->getTableAlias(false,false);
    return array(
        'order'=>"`$alias`.`id` DESC",
    );
}
于 2013-10-03T08:49:38.517 回答