这里是我的DERP时刻,卡住...我有一个Ajax调用去一个控制器动作,我有一个查询比较两个日戳,我得到下面的错误:CakePHP的3 JSON结果查询
前end js loop和ajax
while(count <= toursToday){
tourtimeFormatted = moment.utc(tourtime);
var html = '<button data-id="<?= $tour->id ?>" data-timeslot="'+tourtimeFormatted+'" class="btn btn-default timeSlot">'+formatAMPM(tourtime)+'</button>';
$('#tourDetails').append(html);
tourtime.setMinutes(tourtime.getMinutes() + 30);
console.log(tourtime);
count++;
}
$('body').on('click', 'button.timeSlot', function() {
alert('clicked');
var time = $(this).data('timeslot');
var tour_id = $(this).data('id');
//ajax get avaliable seats
$.ajax({
method: "POST",
url: "/getseats.json",
data: { tour_id: tour_id, date_time: time }
})
.success(function(data) {
});
});
错误和后端显示更多关于正在发生的事情。我觉得我有日期的比较错误的,但我不知道在哪里...
2016-06-15 14:56:29 Error: [BadMethodCallException] Unknown finder method "Array"
Request URL: /getseats.json
Referer URL: http://paddletap.lan/book-a-tour/6
Stack Trace:
#0 /Applications/XAMPP/xamppfiles/htdocs/PaddleTapRedesign/vendor/cakephp/cakephp/src/ORM/Table.php(943): Cake\ORM\Table->callFinder(Array, Object(Cake\ORM\Query), Array)
#1 /Applications/XAMPP/xamppfiles/htdocs/PaddleTapRedesign/src/Controller/TourController.php(98): Cake\ORM\Table->find(Array)
#2 [internal function]: App\Controller\TourController->getseats()
#3 /Applications/XAMPP/xamppfiles/htdocs/PaddleTapRedesign/vendor/cakephp/cakephp/src/Controller/Controller.php(429): call_user_func_array(Array, Array)
#4 /Applications/XAMPP/xamppfiles/htdocs/PaddleTapRedesign/vendor/cakephp/cakephp/src/Routing/Dispatcher.php(114): Cake\Controller\Controller->invokeAction()
#5 /Applications/XAMPP/xamppfiles/htdocs/PaddleTapRedesign/vendor/cakephp/cakephp/src/Routing/Dispatcher.php(87): Cake\Routing\Dispatcher->_invoke(Object(App\Controller\TourController))
#6 /Applications/XAMPP/xamppfiles/htdocs/PaddleTapRedesign/webroot/index.php(37): Cake\Routing\Dispatcher->dispatch(Object(Cake\Network\Request), Object(Cake\Network\Response))
#7 {main}
2016-06-15 15:08:23 Warning: Warning (2): strtolower() expects parameter 1 to be string, array given in [/Applications/XAMPP/xamppfiles/htdocs/PaddleTapRedesign/vendor/cakephp/cakephp/src/ORM/BehaviorRegistry.php, line 215]
Trace:
Cake\Error\BaseErrorHandler::handleError() - CORE/src/Error/BaseErrorHandler.php, line 147
strtolower - [internal], line ??
Cake\ORM\BehaviorRegistry::hasFinder() - CORE/src/ORM/BehaviorRegistry.php, line 215
Cake\ORM\Table::callFinder() - CORE/src/ORM/Table.php, line 1787
Cake\ORM\Table::find() - CORE/src/ORM/Table.php, line 943
App\Controller\TourController::getseats() - APP/Controller/TourController.php, line 98
Cake\Controller\Controller::invokeAction() - CORE/src/Controller/Controller.php, line 429
Cake\Routing\Dispatcher::_invoke() - CORE/src/Routing/Dispatcher.php, line 114
Cake\Routing\Dispatcher::dispatch() - CORE/src/Routing/Dispatcher.php, line 87
[main] - ROOT/webroot/index.php, line 37
public function getseats()
{
$orders = TableRegistry::get('Orders');
$tour_id = $_POST['tour_id'];
$date_time = $_POST['date_time'];
$new_date = date('Y-m-d H:i:s', strtotime($date_time));
//find order items for tour id
$bookings = $orders->find([
'conditions' => [
DATE('Orders.booking_date_time') => $date_time
]
])->all()
;
//where date is M-d-yy
//where time is H:i
$this->set('bookings', $bookings);
$this->set('_serialize', ['bookings']);
}
没有错误说哪一行导致的转换错误?但是当你有像'$ foo = array(); echo $ foo;'或'$ bar ='这会很好地结束。 $ foo' - 在字符串上下文中使用数组。 –
我认为这是查询,传入的是2016-07-17T15:00:00-05:00 –
以下是附在响应中的错误消息: 注意(8):数组到字符串转换[CORE /src/ORM/Table.php,第1782行] 警告(2):strtolower()期望参数1为字符串,数组给定[CORE/src/ORM/BehaviorRegistry.php,第215行] 注意(8)数组到字符串的转换[CORE/src/ORM/Table.php,第1792行] –