我正在使用CakePHP 3.5.14和
我一直在努力让“添加”动作发挥作用。
它在/vendor/cakephp/cakephp/src/View/Helper/FormHelper.php
在字符串
上调用成员函数format()
在第2785行。
$out = $widget->render($data, $this->context());
扩展参数:
[
'formatter' => null,
'prepend' => null,
'append' => null,
'inline' => null,
'type' => 'datetime',
'required' => false,
'options' => null,
'tooltip' => null,
'templateVars' => [],
'id' => 'created',
'second' => false,
'name' => 'created',
'val' => 'CURRENT_TIMESTAMP',
'year' => [
'required' => false,
'order' => 'desc'
],
'month' => [
'required' => false,
'names' => true
],
'day' => [
'required' => false
],
'hour' => [
'required' => false,
'format' => (int) 24
],
'minute' => [
'required' => false,
'interval' => (int) 1,
'round' => null
],
'meridian' => [
'required' => false
]
]
object(Cake\View\Form\EntityContext) {
[protected] _request => object(Cake\Http\ServerRequest) {
params => [
[maximum depth reached]
]
data => [[maximum depth reached]]
query => [[maximum depth reached]]
cookies => [
[maximum depth reached]
]
url => 'users/add'
base => ''
webroot => '/'
here => '/users/add'
trustProxy => false
[protected] _environment => [
[maximum depth reached]
]
[protected] _input => null
[protected] _detectors => [
[maximum depth reached]
]
[protected] _detectorCache => [
[maximum depth reached]
]
[protected] stream => object(Zend\Diactoros\PhpInputStream) {}
[protected] uri => object(Zend\Diactoros\Uri) {}
[protected] session => object(Cake\Network\Session) {}
[protected] attributes => [[maximum depth reached]]
[protected] emulatedAttributes => [
[maximum depth reached]
]
[protected] uploadedFiles => [[maximum depth reached]]
[protected] protocol => null
[protected] requestTarget => null
}
[protected] _context => [
'entity' => object(App\Model\Entity\User) {},
'table' => null,
'validator' => []
]
[protected] _rootName => 'Users'
[protected] _isCollection => false
[protected] _tables => [
'Users' => object(App\Model\Table\UsersTable) {}
]
[protected] _validator => [
'' => object(Cake\Validation\Validator) {}
]
}
我试图直接更改数据库中的各种内容,但无法获得任何可靠的结果
(有时我在删除“DEFAULT_TIMESTAMP
”后进入“添加”页面,但获取了无效的时间戳格式,但无法在第二次测试中重现该行为)
这就是我的Users表的样子
CREATE TABLE `Users` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(25) NOT NULL,
`email` varchar(45) DEFAULT NULL,
`password` varchar(65) NOT NULL,
`created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
由此迁移创建
$this->table('Users')
->addColumn('name', 'string', [
'default' => null,
'limit' => 25,
'null' => false,
])
->addColumn('email', 'string', [
'default' => null,
'limit' => 45,
'null' => true,
])
->addColumn('password', 'string', [
'default' => null,
'limit' => 65,
'null' => false,
])
->addColumn('created', 'timestamp', [
'default' => 'CURRENT_TIMESTAMP',
'limit' => null,
'null' => false,
])
->addColumn('modified', 'timestamp', [
'default' => 'CURRENT_TIMESTAMP',
'update' => 'CURRENT_TIMESTAMP',
'limit' => null,
'null' => false,
])
->create();
我的控制器基本上是空的
class UsersController extends AppController
{
}
因为我已经完成了跟随Crud和crud-view入门指南 我有点卡在这一点,并希望得到任何帮助。
供参考,以下是完整文件的粘贴条:
Migratoin 20180406144732_Initial.php
AppController.php
Stacktrace
Complete Composer show output
如果我遗漏任何信息,请告知我们
谢谢和问候,
Minzkraut
答案 0 :(得分:1)
我相信 CakePHP希望这些字段是日期时间字段,而不是时间戳。如果你改变它,它应该按预期工作。
同样,虽然你当然可以设置默认值/更新值,因为它是时间戳,你需要更改它们,或者让CakePHP ORM通过TimestampBehavior
处理它们。