Cake 3.x的Class TypeMap中使用的可接受类型是什么? [英] What are the acceptable types used in the Class TypeMap in Cake 3.x?

查看:69
本文介绍了Cake 3.x的Class TypeMap中使用的可接受类型是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用蛋糕3.2.4

使用方法 addDefaults()设置类型 decimal .想知道以下内容:

Was using the method addDefaults() to set the type decimal. Was wondering the following:

  1. 我还能设置什么其他类型?
  2. 在方法 addDefaults()
  3. 中设置小数时是否可以设置精度和小数位数
  1. what other types are there that I can set?
  2. 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>数据库访问&ORM>数据库基础>数据类型

Cookbook > Database Access & ORM > Database Basics > Data Types

并在源代码中

在方法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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆