我想知道$reservation_datetime
有多少預訂。我寫了這個代碼,但是我有錯誤Zend Framework 2 TableGateway Select error
Catchable fatal error: Argument 1 passed to Reservations\Model\ReservationTable::Reservations\Model{closure}() must be an instance of Reservations\Model\Select, instance of Zend\Db\Sql\Select given, called in /home/.../vendor/zendframework/zend-db/src/TableGateway/AbstractTableGateway.php on line 190 and defined in /home/.../module/Reservations/src/Reservations/Model/ReservationTable.php on line 99
線99:
$this->num = $this->tableGateway->select(function (Select $select) {
$select->columns(array('num' => new \Zend\Db\Sql\Expression('COUNT(*)')));
$select->where(array('reservation_date' => $reservation_datetime));
});
這個代碼
class ReservationTable
{
protected $tableGateway;
public function __construct(TableGateway $tableGateway)
{
$this->tableGateway = $tableGateway;
}
public function saveReservation(Reservation $reservation)
{
$data = array(
'reservation_date' => $reservation_datetime,
...
);
$reservation_spot = (int)1;
$rsn = $this->getReservationCount($reservation_datetime);
if($rsn < 4) {
for($i=1; $i<4; $i++){
if($rsn = $i) {
$reservation_spot++;
}
}
}
else {
throw new \Exception('No available spots');
}
}
public function getReservationCount($reservation_datetime)
{
$this->num = $this->tableGateway->select(function (Select $select) {
$select->columns(array('num' => new \Zend\Db\Sql\Expression('COUNT(*)')));
$select->where(array('reservation_date' => $reservation_datetime));
});
return $this->num;
}
}