使用cgridview在顶部显示新条目yii

时间:2013-07-19 05:55:48

标签: yii

我是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,
        ));

1 个答案:

答案 0 :(得分: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 for jb model

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