属性CActiveDataProvider.Select未在YII中定义

时间:2013-09-18 04:52:06

标签: php activerecord yii cactivedataprovider

我有一个名为Activity的模型,其中的search()定义如下。但我不能想到为什么当我这样称呼这个错误提示..

内部服务器错误 未定义属性“CActiveDataProvider.select”。

呼唤方式..

//获取数据   $ model = new $ modelName();   if($ modelName ===“Activity”)      $ criteria = $ model-> search();   其他      $ criteria = unserialize(base64_decode($ criteria));

$rows = $model->commandBuilder->createFindCommand($model->tableSchema, $criteria)->queryAll();

我在这里做错了什么?任何人都可以帮我解决这个问题

   public function search() {
      $criteria = new CDbCriteria();
      $criteria->select = 't.id,t.activity_id,t.type,t.sub_type,t.name,t.description,t.source,t.delete_req,t.delete_reason,s.id as session_id, s.site_id, 
      s.location, s.start_time, s.end_time, j.id as Participants as s.closed, c.first_name, j.attended, c.managed_by_id';
      $criteria->join = 'left join activity_sessions s on t.id = s.activities_id 
         left join activity_jobseekers j on s.id = j.session_id
         left join contacts c on j.contact_id = c.id';
      // Case insensitive compare
      if (!empty($this->activity_id))
         $criteria->addSearchCondition("t.activity_id", $this->activity_id.'%', false, 'AND', 'ILIKE');
      if (!empty($this->type))
         $criteria->addSearchCondition("t.type", $this->type.'%', false, 'AND', 'ILIKE');
      if (!empty($this->sub_type))
         $criteria->addSearchCondition("t.sub_type", $this->sub_type.'%', false, 'AND', 'ILIKE');
      if (!empty($this->name))
         $criteria->addSearchCondition("t.name", $this->name.'%', false, 'AND', 'ILIKE');
      if (!empty($this->description))
         $criteria->addSearchCondition("t.description", $this->description.'%', false, 'AND', 'ILIKE');
      if ($this->source !== null)
         $criteria->compare('t.source', $this->source, false);

      $criteria->addCondition("t.delete_req='0'");

      return new CActiveDataProvider('Activity', array(
         'criteria'=>$criteria,
         'sort'=>array('defaultOrder'=>'t.id ASC'),
         'pagination'=>array('pageSize'=>Yii::app()->params['DefaultPageSize']),
      ));
   }

1 个答案:

答案 0 :(得分:2)

U应返回 CDbCriteria 对象,而不是在搜索方法中返回 CActiveDataProvider 提供程序对象。

希望这会有所帮助..