Php Yii 2中的标准、活动数据提供程序、CDBC标准?
我正在尝试将此部分下面的代码转移到Php Yii 2中的标准、活动数据提供程序、CDBC标准?,php,yii,Php,Yii,我正在尝试将此部分下面的代码转移到yii2。它适用于控制器上的Yii1,但我已经读到,我不需要Yii2中的标准,因为它已经不存在了。有人能告诉我如何在yii2中运行它吗? 在yii2中,CDBCriteria作为ActiveQuery或Query使用是否更好 public function search() { $criteria=new CDbCriteria; $criteria->compare('id',$this->id);
yii2
。它适用于控制器上的Yii
1,但我已经读到,我不需要Yii2中的标准,因为它已经不存在了。有人能告诉我如何在yii2中运行它吗?
在yii2中,CDBCriteria
作为ActiveQuery
或Query
使用是否更好
public function search()
{
$criteria=new CDbCriteria;
$criteria->compare('id',$this->id);
$criteria->compare('hashkey',$this->hashkey,true);
$criteria->compare('ch',$this->ch,true);
$criteria->compare('cimi',$this->cimi,true);
$criteria->compare('dir',$this->dir,true);
$criteria->compare('ourl',$this->ourl,true);
$criteria->compare('imob',$this->imob,true);
$criteria->compare('tStart',$this->tStart,true);
$criteria->compare('tAnswer',$this->tAnswer,true);
$criteria->compare('tEnd',$this->tEnd,true);
$criteria->compare('state',$this->state,true);
$criteria->compare('omob',$this->omob,true);
$criteria->compare('date',$this->date,true);
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
));
}
public static function model($className=__CLASS__)
{
return parent::model($className);
}
public function getInCalls($fromDate = false, $toDate = false) {
$rawData = Yii::$app->db->createCommand ( "select id, date as Date, ch as Channel, dir as Direction, ourl as Twinkle, imob as IncomingCall, state as State from logs where tAnswer like '%+%' group by date order by date desc" )->queryAll ();
return $rawData;
}
public function getOutCalls($fromDate = false, $toDate = false) {
$rawData = Yii::$app->db->createCommand ( "select id, date as Date, ch as Channel, dir as Direction, ourl as Twinkle, state as State, omob as OutgoingCall from logs where state like 'Mobile%' and (
omob like '07%' or omob like '+%') group by date order by date desc" )->queryAll ();
return $rawData;
}
public function getMissedCalls($fromDate = false, $toDate = false) {
$rawData = Yii::$app->db->createCommand ( "select id, date as Date, ch as Channel, state as State, imob as Missed, ourl as Agent from logs where tEnd like '%+%' and imob is not null and state like '%Lan%' and tAnswer not like '%+%' and (imob like '07%' or imob like '+%') group by date order by date desc" )->queryAll ();
return $rawData;
}
return $rawData;
}
public function getOutCalls($fromDate = false, $toDate = false) {
$rawData = Yii::app ()->db->createCommand ( "select id, date as Date, ch as Channel, dir as Direction, ourl as Twinkle, state as State, omob as OutgoingCall from logs where state like 'Mobile%' and (omob like '07%' or omob like '+%') group by date order by date desc" )->queryAll ();
return $rawData;
}
public function getMissedCalls($fromDate = false, $toDate = false) {
$rawData = Yii::app ()->db->createCommand ( "select id, date as Date, ch as Channel, state as State, imob as Missed, ourl as Agent from logs where tEnd like '%+%' and imob is not null and state like '%Lan%' and tAnswer not like '%+%' and (imob like '07%' or imob like '+%') group by date order by date desc" )->queryAll ();
return $rawData;
}
谢谢您可以使用gii生成的代码在modelSearch类中看到一个典型的过滤器查询(您应该使用此工具) 无论如何,假设您有一个名为MyModel的模型,Yii2的tipycal搜索函数基于数据提供程序和筛选条件,例如:
public function search($params)
{
$query = MyModel::find();
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
if (!($this->load($params) && $this->validate())) {
return $dataProvider;
}
$query->andFilterWhere([
'id' => $this->id,
]);
$query->andFilterWhere(['like', 'your_att1', $this->your_att1])
......
->andFilterWhere(['like', 'your_attN', $this->your_attN]);
return $dataProvider;
}
在您的情况下,似乎所有的列都不是字符串编号
公共函数搜索()
{
.一步一步地描述。
$query = MyModel::find();
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
$query->andFilterWhere(['id' => $this->id ])
->andFilterWhere(['hashkey' => $this->hashkey ])
->andFilterWhere(['ch' => $this->ch ])
.....
->andFilterWhere(['date' => $this->date ]);
return $dataProvider;
}