1
我想用兩個表的聯合創建分頁,但出現以下錯誤:調用一個成員函數工會()一個非對象在yii2
Call to a member function union() on a non-object
$query1=Mobile::find()->select('video')->all();
$query2=Tablet::find()->select('video')->all();
$count=Mobile::find()->count();
$query = (new Query)
->select('*')
->from([
$query1->union($query2),
])
->limit(3);
我怎麼可以聯合2這個框架中的表?
[?參考 - 這是什麼錯誤PHP意味着]的可能的複製(https://stackoverflow.com/questions/12769982/reference-what-does-this-error -mean-in-php) – BenRoob
$ query1用作$ query(from method)中的子查詢,不是ActiveQuery istance,而是一組Mobile數據模型。您應該將$ query1聲明爲Mobile :: find() - > select('video'),而不必在最後調用all()。 –