0

我有两个搜索功能。一种用于公共搜索,另一种用于管理员搜索。它们完全相同:

public function search()
{
        // @todo Please modify the following code to remove attributes that should not be searched.

        $criteria=new CDbCriteria;

        //$criteria->compare('ID',$this->ID);
        $criteria->compare('t.IDkorisnik',Yii::app()->user->getId());
        $criteria->compare('start_time',$this->start_time,true);
        $criteria->compare('end_time',$this->end_time,true);
        //$criteria->compare('information',$this->information,true);
        $criteria->compare('country',$this->country,true);
        $criteria->compare('city',$this->city,true);
        $criteria->compare('start_price',$this->start_price);
        $criteria->compare('min_bid',$this->min_bid);
        $criteria->compare('valuta',$this->valuta,true);
        $criteria->compare('title',$this->title,true);

        $criteria->with=array('relationIDuzgajivac','relationIDgolub');
        $criteria->compare('username',$this->uzgajivacSearch);
        $criteria->compare('brojgoluba',$this->golub_search, true);

        return new CActiveDataProvider($this, array(
                'criteria'=>$criteria,
                'pagination'=>array('pageSize'=>50),
        ));
}

除了在 search() 我有这个

$criteria->compare('t.IDkorisnik',Yii::app()->user->getId());

在 publichsearch() 我没有。

如您所见,有关系搜索。当我打开管理页面时它在公共搜索页面中工作它不起作用,我不知道为什么

4

1 回答 1

0

我从未意识到当我创建新动作时

public function actionPublicSearch()
{

    $model=new Auction('search');
    $model->unsetAttributes();  // clear any default values
    if(isset($_GET['Auction']))
        $model->attributes=$_GET['Auction'];

    $this->render('publicsearch',array(
        'model'=>$model,
    ));
}

$model=new Auction('search');在模型中总是必须是“搜索”而不是像“public_search”这样的东西

然后在视图中创建 CGridView

<?php $this->widget('zii.widgets.grid.CGridView', array(
    'id'=>'auction-grid',
    'dataProvider'=>$model->public_search(),

dataProvider 是我放置搜索功能的地方,在本例中为 public_search

于 2013-09-13T18:40:31.797 回答