TYPO3中的userFunc显示呈现的列表,但不存储在DB中



我的一条记录的TCA字段如下:

'page_id' => array(
            'exclude' => 0,
            'label' => 'LLL:EXT:calendar/Resources/Private/Language/locallang_db.xlf:tx_calendar_domain_model_display.page_id',
            'config' => array(
                'type' => 'user',
                'userFunc' => 'EXT:calendar/class.tx_calendars_tca.php:tx_calendars_tca->someWizard',
            ),

函数someWizard看起来像这样:

    function someWizard($PA, $fObj) {

        $content='<select>' .
                '<option value="One" > item 1 </option>' .
                '<option value="Two" > item 2 </option>' .
                '<option value="Three" > item 55 </option>' .
                '</select>';

        return $content;
}

选择列表在后端表单中呈现得很好,但在保存时不存储任何内容。可能是显示了列表,但没有设置值。

编辑:

我试图得到所有的页面标题到一个下拉列表,与一些条件和处理。我想要做的伪代码是这样的。(我仍然需要对列表做大量的处理)

function someWizard($PA, $fObj) {

                $GLOBALS['TYPO3_DB']->debugOutput = TRUE;
                $formField='<select>';  
                 $PA['fieldConf']['config']['type'] = 'select';
                try{
                    $where='is_siteroot=1';
                    $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*','pages',$where);
                    while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
                        $formField.='<option value='.$row['uid'].'>'.$row['title'].'</option>';
                    }
                }
                catch(Exception $e){
                    echo $e;
                }

                $formField.='</select>';
                return $formField;
    }

如果在我的TCA,我给'type' => 'select'它不渲染任何东西。

您使用的代码当然只会显示选择器。即使这个构造能够保存数据,您也必须至少提供一些关于在哪里存储数据的基本信息。因此,至少为select添加一个"name"属性会很酷。

您应该将字段类型更改为"select"而不是user,并使用itemsProcFunc来操作可用项的数组。

查看更多信息:http://docs.typo3.org/typo3cms/TCAReference/

该元素没有名称,因此没有机会被存储。如果您只想修改列表中的项目,请使用Joey的答案。如果你想根据一些标准来改变字段的配置(例如,从有很多项的选择框到只有很少项的复选框),最好的方法是使用TYPO3的方法来创建元素:

function someWizard($PA, $fObj) {
  $PA['fieldConf']['config']['type'] = 'select';
  $content = $fobj->getSingleField_typeInput('TABLE_NAME', $PA['field'], false, $PA);
  return $content;
}
  • TABLE_NAME替换为表名
  • 在TCA设置中保留所有其他默认配置。
  • 调试$PA,看看里面是什么,你应该改变什么。

最新更新