我有一个字段定义如下:
max_items int(11) NULL
如果你在后端将此字段留空,我希望它存储NULL。
为此,我在TCA中使用此配置,这不起作用:
'max_items' => array(
'exclude' => 0,
'label' => '...',
'config' => array(
'type' => 'input',
'eval' => 'null',
),
),
编辑:它存储NULL
而不是存储预期值0
。我试过max_items int(11) DEFAULT NULL
,但那也不起作用。
Edit2:谢谢你!我最终编写了自己的eval函数:
<?php
class tx_myextension_evalfunc {
function evaluateFieldValue($sValue, $aIsIn, &$bSet)
{
return ($sValue === '') ? null : $sValue;
}
}
?>
使用此配置:
'max_items' => array(
'exclude' => 0,
'label' => '...',
'config' => array(
'type' => 'input',
'eval' => 'tx_myextension_evalfunc',
),
),
这个bug是TYPO3 6.0及更高版本中的fixed。在TCA配置中有一个新的eval选项“null”:
'config' = array(
'type' => 'input',
'eval' => 'null',
...
);
如果启用此选项,则输入右侧会出现一个复选框。如果它被取消激活,则NULL值将保存到数据库中,如果激活,则可以输入整数值。
如果您希望取消激活默认情况下的复选框以将Null存储为默认值,请为其添加“default”=> null:
'config' = array(
'type' => 'input',
'eval' => 'null',
'default' => null,
);
在TYPO3 8 LTS中测试过。然后它看起来像这样:
原始答案:
有两个有趣的链接: