我有兩個表:電話,手機Yii2轉換的SqlDataProvider到ActiveDataProvider與左連接
有兩種型號:通話,語音通話
和下面的代碼:
$q = 'select
c.calling, sp.name as srcname, sp.org as srcorg,
c.called, dp.name as dstname, dp.org as dstorg
from Calls c
left join Phones sp on c.calling = sp.num
left join Phones dp on c.called = dp.num ORDER BY c.time '
$sql = Yii:$app->db->createCommand($q)
$count = $sql->queryScalar();
$dataProvider = new SqlDataProvider([
'sql' => $q,
'pagination' => [
'pageSize' => 25,
],
'totalCount' => $count,
]);
如何將其轉換到ActiveDataProvider查詢?
$dataProvder = new ActiveDataProvider([
'query' => Call::find()->...,
'pagination' => [
'pageSize' => 25,
],
]);
感謝您的詳細解答!我的問題是如何使用 - > join()或 - > leftJoin()在ActiveDataProvider上進行「連接」查詢? – epema
以及如何輸出從連接中獲得的列? – epema
不客氣!我用你想要的信息擴展了我的答案。正如它在我看來,你應該真的閱讀Yii2的模型和ActiveRecord概念的文檔!我在我的答案的第一段中將兩者聯繫起來。我向你保證,你的所有問題都將隨之消失!否則,只需寫另一條評論:)! – PLM57