Home >Backend Development >PHP Tutorial >Yii adds your own search criteria

Yii adds your own search criteria

WBOY
WBOYOriginal
2016-08-08 09:23:011143browse
public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('usertest_id',$this->usertest_id,true);
		$criteria->compare('usertest_project',$this->usertest_project,true);
		$criteria->compare('usertest_imei',$this->usertest_imei,true);
		//$criteria->compare('usertest_sw',$this->usertest_sw,true);
		
		$whereSql = "usertest_sw like '"; //Y2A5HA80BR20 Y2A5GD80BR10 Y2A5*80BR20 usertest_sw like '%Y2A5%80BR20%'
		$keyword = $this->usertest_sw;
		$keyarr=explode('*',$keyword); 
		for($index = 0; $index < count($keyarr); $index++) { 
			$whereSql .= "%$keyarr[$index]";
		} 
		$whereSql .= "%&#39;";
		$criteria->addCondition($whereSql);
		
		
		$criteria->compare('usertest_package',$this->usertest_package,true);
		$criteria->compare('usertest_type',$this->usertest_type,true);
		$criteria->compare('usertest_logtime',$this->usertest_logtime,true);
		$criteria->compare('usertest_cu',$this->usertest_cu,true);
		$criteria->compare('usertest_localtime',$this->usertest_localtime,true);
		$criteria->compare('usertest_logpath',$this->usertest_logpath,true);
		$criteria->compare('usertest_logkeyinfo',$this->usertest_logkeyinfo,true);
		$criteria->compare('usertest_bugid',$this->usertest_bugid,true);
		$criteria->compare('usertest_bugstatus',$this->usertest_bugstatus,true);
		$criteria->compare('usertest_comments',$this->usertest_comments,true);
		$criteria->compare('usertest_userinfo',$this->usertest_userinfo,true);
		$criteria->compare('usertest_repeatcount',$this->usertest_repeatcount,true);
		
		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
			'sort'=>array(
		        'defaultOrder'=>'usertest_logtime desc',
		    ),
		));
	}

The above introduces how to add your own search conditions in Yii, including the content. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn