使用Yii框架2.0我试图从我的关系数据库表中检索数据,遵循此处的文档http://www.yiiframework.com/doc-2.0/guide-db-active-record.html
下面是Lazy和Eager Loading部分下的代码示例 .
$customers = Customer::find()->limit(100)->with([
'orders' => function($query) {
$query->andWhere('subtotal>100');
},
])->all();
在我的情况下,我想将参数传递给andWhere()方法,如下所示 .
$param = 'something flexible';
$customers = Customer::find()->limit(100)->with([
'orders' => function($query) {
$query->andWhere('subtotal > ' . $param);
},
])->all();
它没有这种方式 . 我想念什么或如何将参数从第一行传递给andWhere()方法?
1 回答
我发现解决方案如下 .