Cake 3.x的Class TypeMap中使用的可接受类型是什么? [英] What are the acceptable types used in the Class TypeMap in Cake 3.x?
问题描述
使用蛋糕3.2.4
使用方法 addDefaults()
设置类型 decimal
.想知道以下内容:
Was using the method addDefaults()
to set the type decimal
. Was wondering the following:
- 我还能设置什么其他类型?
- 在方法
addDefaults()
中设置小数时是否可以设置精度和小数位数
- what other types are there that I can set?
- is it possible to set precision and scale when setting decimal in the method
addDefaults()
提示这种想法的代码
$this->paginate['fields'] = [
'id', 'title',
'start' => 'start_date',
'end' => 'end_date',
'revenue',
'costs' => 'total_costs', 'collections'
];
$paginationQuery = $event->subject()->query;
$paginationQuery
->selectTypeMap()
->addDefaults([
'start' => 'datetime',
'end' => 'datetime',
'costs' => 'decimal'
]);
我尝试过的
我尝试研究文档
http://api.cakephp.org/3.2/class-Cake.Database.TypeMap.html#_addDefaults
以及类本身 http://api.cakephp.org/3.2/source-class-Cake.Database.TypeMap.html#17-149
无济于事.
推荐答案
我还能设置什么其他类型?
what other types are there that I can set?
可以在食谱中找到可用的类型
The available types can be found in the cookbook
Cookbook > Database Access & ORM > Database Basics > Data Types
并在源代码中
- https://github.com/cakephp/cakephp/tree/3.2.5/src/Database/Type
- https://github.com/cakephp/cakephp/blob/3.2.5/src/Database/Type.php#L27-L64
在方法addDefaults()中设置小数时是否可以设置精度和小数位数
is it possible to set precision and scale when setting decimal in the method addDefaults()
正如评论中提到的那样,PHP吞下了尾随零位小数,这就是它的工作原理,如果您想保留"它们,那么在输出它们时应该格式化它们.
As mentioned in the comments, PHP swallows trailing zero decimals, that's just how it works, if you want to "keep" them, then you should format the numbers when outputting them.
Cookbook > Number > Formatting Numbers
这篇关于Cake 3.x的Class TypeMap中使用的可接受类型是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!