cake php 3.8.8 Невозможно преобразовать значение типа `строка` в целое число при сохранении крайнего срока поля в качестве даты и времени - PullRequest
0 голосов
/ 23 января 2020

Cake php не сохраняет выбранное значение поля даты. У меня есть форма с полем типа:

<? echo $this->Form->control('deadline', ['class' => 'form-control text-form-control', 'type' => 'datetime']); ?>

Я могу редактировать и изменять дату с существующей задачей в базе данных, но при добавлении новой задачи я есть ошибка с массажем:

Cannot convert value of type `string` to integer
InvalidArgumentException

В табличной модели у меня есть:

<?php
 public function beforeMarshal(Event $event, ArrayObject $data, ArrayObject $options) {
    foreach (['deadline'] as $key) {
        if (isset($data[$key]) && is_array($data[$key])) {
            $data[$key] = strtotime($data[$key]['year'] . '-' . $data[$key]['month'] . '-' . $data[$key]['day'] . ' ' . $data[$key]['hour'] . ':' . $data[$key]['minute']);
        }
    }
}
?>

Трассировка стека:

Error: [InvalidArgumentException] Cannot convert value of type `string` to integer (\vendor\cakephp\cakephp\src\Database\Type\IntegerType.php:72)
#0 \vendor\cakephp\cakephp\src\Database\Type\IntegerType.php(91): Cake\Database\Type\IntegerType->checkNumeric('2020-01-23 15:5...')
#1 \vendor\cakephp\cakephp\src\Database\TypeConverterTrait.php(36): Cake\Database\Type\IntegerType->toDatabase('2020-01-23 15:5...', Object(Cake\Database\Driver\Mysql))
#2 \vendor\cakephp\cakephp\src\Database\Statement\PDOStatement.php(68): Cake\Database\Statement\StatementDecorator->cast('2020-01-23 15:5...', 'integer')
#3 \vendor\cakephp\cakephp\src\Database\ValueBinder.php(146): Cake\Database\Statement\PDOStatement->bindValue('c7', '2020-01-23 15:5...', 'integer')
#4 \vendor\cakephp\cakephp\src\Database\Connection.php(332): Cake\Database\ValueBinder->attachTo(Object(Cake\Database\Statement\MysqlStatement))
#5 \vendor\cakephp\cakephp\src\Core\Retry\CommandRetry.php(67): Cake\Database\Connection->Cake\Database\{closure}()
#6 \vendor\cakephp\cakephp\src\Database\Connection.php(336): Cake\Core\Retry\CommandRetry->run(Object(Closure))
#7 \vendor\cakephp\cakephp\src\Database\Query.php(218): Cake\Database\Connection->run(Object(Cake\ORM\Query))
#8 \vendor\cakephp\cakephp\src\ORM\Table.php(2129): Cake\Database\Query->execute()
#9 \vendor\cakephp\cakephp\src\ORM\Table.php(2021): Cake\ORM\Table->_insert(Object(App\Model\Entity\Task), Array)
#10 \vendor\cakephp\cakephp\src\ORM\Table.php(1934): Cake\ORM\Table->_processSave(Object(App\Model\Entity\Task), Object(ArrayObject))
#11 \vendor\cakephp\cakephp\src\ORM\Table.php(1639): Cake\ORM\Table->Cake\ORM\{closure}()
#12 \vendor\cakephp\cakephp\src\Database\Connection.php(737): Cake\ORM\Table->Cake\ORM\{closure}(Object(Cake\Database\Connection))
#13 \vendor\cakephp\cakephp\src\ORM\Table.php(1640): Cake\Database\Connection->transactional(Object(Closure))
#14 \vendor\cakephp\cakephp\src\ORM\Table.php(1935): Cake\ORM\Table->_executeTransaction(Object(Closure), true)
#15 \src\Controller\TasksController.php(65): Cake\ORM\Table->save(Object(App\Model\Entity\Task))
#16 \vendor\cakephp\cakephp\src\Controller\Controller.php(609): App\Controller\TasksController->add()
...