echo $slot->id;
$slot->players = (Model_Players::find(function ($query)
{
return $query->join('users')
->on('players.player', '=', 'users.id')
->where('players.slot', $slot->id);
})) ?: array();
返回:
4
ErrorException [ Notice ]: Undefined variable: slot
APPPATH/classes/controller/booking.php @ line 98:
98: ->where('players.slot', $slot->id);
如何将$slot
对象发送到函数中?
答案 0 :(得分:2)
您必须在查询中“使用”$ slot变量
echo $slot->id;
$slot->players = (Model_Players::find(function ($query) use ($slot)
{
return $query->join('users')
->on('players.player', '=', 'users.id')
->where('players.slot', $slot->id);
})) ?: array();
答案 1 :(得分:1)
需要使用use
。
Model_Players::find(function ($query) use ($slot)
干杯。