I want to know how many reservations are made at $reservation_datetime
. I wrote this code however I have 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
The line 99 is:
$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));
});
Of this code
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;
}
}