What are the acceptable types used in the Class TypeMap in Cake 3.x?

大城市里の小女人 提交于 2019-12-12 04:16:14

问题


Situation

using cake 3.2.4

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

  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()

Code that prompted that thinking

       $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'
        ]);

What I tried

I tried researching the docs

http://api.cakephp.org/3.2/class-Cake.Database.TypeMap.html#_addDefaults

and also the class itself http://api.cakephp.org/3.2/source-class-Cake.Database.TypeMap.html#17-149

To no avail.


回答1:


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

and in the source

  • 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

is it possible to set precision and scale when setting decimal in the method addDefaults()

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



来源:https://stackoverflow.com/questions/35973135/what-are-the-acceptable-types-used-in-the-class-typemap-in-cake-3-x

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!