0
當添加收入或費用時,兩個條目在名爲TabGLEntry的表中完成(兩個條目具有最相似的值,但借記卡,信用卡都具有相同的憑證號)。我想要顯示TabGLEntry的值(每個憑單號只應顯示一個值)。所以這是我對這種情況下的SQL查詢在Yii2中查詢內部搜索功能
SELECT *
FROM `tabGLEntry`
GROUP BY `voucher_no`
當我試圖在我的數據庫它的工作原理。現在,來實現它在Yii2 我想這在查詢檢索模型(TabglentrySearch.php)
public function search_all($params)
{
//~ $query = TabGLEntry::find();
$query = TabGLEntry::find()->groupBy(['voucher_no'])->all();
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
$this->load($params);
if (!$this->validate()) {
// uncomment the following line if you do not want to return any records when validation fails
// $query->where('0=1');
return $dataProvider;
}
$query->andFilterWhere([
'id' => $this->id,
'creation' => $this->creation,
'modified' => $this->modified,
'voucher_category' => $this->voucher_category,
'credit' => $this->credit,
'transaction_date' => $this->transaction_date,
'clearance_date' => $this->clearance_date,
'debit' => $this->debit,
'posting_date' => $this->posting_date,
'payment_method_id' => $this->payment_method_id,
'reference_date' => $this->reference_date,
'is_editable' => $this->is_editable,
'created_by' => $this->created_by,
'created_at' => $this->created_at,
'updated_by' => $this->updated_by,
'updated_at' => $this->updated_at,
'is_deleted' => $this->is_deleted,
]);
$query->andFilterWhere(['like', 'name', $this->name])
->andFilterWhere(['like', 'entity_name', $this->entity_name])
->andFilterWhere(['like', 'modified_by', $this->modified_by])
->andFilterWhere(['like', 'account', $this->account])
->andFilterWhere(['like', 'fiscal_year', $this->fiscal_year])
->andFilterWhere(['like', 'against_voucher', $this->against_voucher])
->andFilterWhere(['like', 'against_voucher_type', $this->against_voucher_type])
->andFilterWhere(['like', 'is_opening', $this->is_opening])
->andFilterWhere(['like', 'against', $this->against])
->andFilterWhere(['like', 'voucher_type', $this->voucher_type])
->andFilterWhere(['like', 'is_advance', $this->is_advance])
->andFilterWhere(['like', 'remarks', $this->remarks])
->andFilterWhere(['like', 'cost_center', $this->cost_center])
->andFilterWhere(['like', 'reference_no', $this->reference_no])
->andFilterWhere(['like', 'voucher_no', $this->voucher_no]);
return $dataProvider;
}
,現在我得到一個錯誤
PHP Fatal Error – yii\base\ErrorException
Call to a member function andFilterWhere() on a non-object
此表中是否有任何外鍵?如果你可以在這裏添加'model'代碼,那將會很好。 –