0
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对象发送到函数中?

4

2 回答 2

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();
于 2012-11-06T19:37:47.297 回答
1

需要使用use

Model_Players::find(function ($query) use ($slot) 

干杯。

于 2012-11-06T20:44:29.507 回答