0
上午通過yii2創建命令傳遞原始的sql命令,但我總是得到一個錯誤的屬性必須是實現QueryInterface的類的一個實例,例如警予\ DB \查詢或它的子類將原始sql傳遞給yii2活動數據提供者
這是代碼
$sql ="
SELECT
tblpritems.PRlineID
, tblpritems.Tracking_Code
, tblpritems.Description
, tblpritems.Quantity
, tblpritems.Unit_Price
, tblpritems.Extended_price
, tblpritems.PRID
, tblpritems.pr_solicitation_id
, tblpritems.date_item_received
, tblpritems.Quantity_received
, tblpritems.Remarks_on_receipt
, tblpritems.Received_by
FROM
prts.tblpritems
INNER JOIN prts.tblpr
ON (tblpritems.PRID = tblpr.PRID)
INNER JOIN prts.tblprsolicitations
ON (tblprsolicitations.PRID = tblpr.PRID) AND (tblpritems.pr_solicitation_id = tblprsolicitations.pr_solicitation_id)
INNER JOIN prts.tblprsuppliers
ON (tblprsuppliers.pr_solicitation_id = tblprsolicitations.pr_solicitation_id)
INNER JOIN prts.tblpo
ON (tblpo.pr_supplier_id = tblprsuppliers.pr_supplier_id)
where tblpr.PRID=".$val." and tblpo.PO_Status_ID=7 and item_received_status=0
";
$connection = Yii::$app->getDb();
$command = $connection->createCommand($sql);
$result = $command->query();
$dataProvider = new ActiveDataProvider([
'query' => $result,
]);
當我嘗試的var_dump($數據提供程序),這就是當它返回錯誤
'$命令 - >查詢()'返回DataReader的,不Query'的'實例。使用'SqlDataProvider'而不是活動的。 – ineersa
問題是,我想要顯示相關記錄,但sql的dataProvider返回一個數組 –