我可以在_schema Model字段中放置什么来构建自定义无表格模型?

Fir*_*DoL 0 cakephp model cakephp-2.1

我已经在食谱中读到了这个"技巧":http://book.cakephp.org/2.0/en/models/model-attributes.html#usetable

现在我想为我的模型构建一个自定义模式,但是没有这个数组的格式.例如,我不知道我应该为bool类型添加什么:"boolean"或"bool"?

如果我想在使用$ this-> Form-> input时获得"选择框",我应该放什么类型?我应该创建一个hasMany关系(有2个无表格模型)吗?

mar*_*ark 7

文档在这里:http://book.cakephp.org/2.0/en/models/model-attributes.html#schema

以下是联系表格的示例:http: //www.dereuromark.de/2011/12/15/tools-plugin-part-2-contact-form/

至于布尔(tinyint 1):

protected $_schema = array(
   'status' => array(
       'type' => 'boolean',
       'length' => 1,
       'default' => 0,
       'null' => false,
       'comment' => 'some optional comment'
   ),   
);
Run Code Online (Sandbox Code Playgroud)

TIPP:如果你想快速找到这个:

创建一个表"apples"和一个Apple模型并添加要调试的所有类型的字段然后调用模型schema(),如下所示:

debug($this->Apple->schema());
Run Code Online (Sandbox Code Playgroud)

这是我如何证实以上内容.

对于第二部分 - 如果值可以被视为"静态",我使用以下ENUM解决方案来选择框:http: //www.dereuromark.de/2010/06/24/static-enums-or-semihardcoded -attributes / 否则你应该使用cookbook或数组数据源中记录的关系.