使用foreign_table从一个表中获取数据,并在TCA中更新到另一个表

时间:2012-06-28 15:38:26

标签: typo3

我正在修改图片上传扩展程序,而我正在开发一个可以将图片放在类别中的功能。

现在,类别列在选择字段中,该字段使用foreign_table从表中获取类别(称为tx_gallery_categories),保存时类别Id(选项字段中的值)保存到名为tx_gallery_items的表中。

但不再需要那个专栏(我第一次错了)。根据您选择的类别,我希望TCA更新名为tx_gallery_itemsCategory的表,并设置categoryId,其中itemId等于保存的图像uid

这是TCA(我删除了categoryId旁边的所有其他列)和categoryId是我想要从中移出的那个,我想,并且它自己的TCA连接到tx_gallery_itemsCategory:

$TCA["tx_gallery_items"] = array (
"ctrl" => $TCA["tx_gallery_items"]["ctrl"],
"interface" => array (
    "showRecordFieldList" => "hidden,oid,filename, videoembedcode,caption"
),
"feInterface" => $TCA["tx_gallery_items"]["feInterface"],
"columns" => array (
    "categoryId" => Array (     
        "exclude" => 1,     
        "label" => "LLL:EXT:gc_gallery/locallang_db.xml:tx_gallery_items.categories",       
        "config" => Array (
            "type" => "select",
            "foreign_table" => "tx_gallery_categories",
            // "foreign_table_where" => " true"
            // "itemsProcFunc" => "tx_gallery_getImageCategories->getCategories"
            // 'default' => '123'
        )
    ),
),
"types" => array (
    "0" => array("showitem" => "hidden, oid, filename, categoryId, videoembedcode, caption, linkpid")
)
);

$TCA["tx_gallery_categories"] = array (
"ctrl" => $TCA["tx_gallery_categories"]["ctrl"],
"interface" => array (
    "showRecordFieldList" => "categoryTitle"
),
"feInterface" => $TCA["tx_gallery_categories"]["feInterface"],
"columns" => array (
    "categoryTitle" => Array (      
        "exclude" => 0,     
        "label" => "LLL:EXT:gc_gallery/locallang_db.xml:tx_gallery_items.categories",       
        "config" => Array (
            "type" => "text",
            "cols" => "30", 
            "rows" => "5",
        )
    )
),
"types" => array (
    "0" => array("showitem" => "categoryTitle")
)

);

但是我没有像我那样工作,而是想将图像uid从tx_gallery_items保存到另一个名为tx_gallery_itemsCategory的表,这是tx_gallery_items和tx_gallery_categories之间的多对多表

以下是表格:

tx_gallery_items:
  uid | pid | ... (and many more but only uid is relevant)
  432 | 34  | ...

tx_gallery_itemsCategory:
  id | itemId | categoryId
  1  | 432    | 1

tx_gallery_categories:
  uid | pid | categoryTitle   
  1   | 34  | example category 

这是ext_tables.php

$TCA["tx_gallery_items"] = array (
"ctrl" => array (
    'title'     => 'LLL:EXT:gc_gallery/locallang_db.xml:tx_gallery_items',
    'label'     => 'filename',
    'tstamp'    => 'tstamp',
    'crdate'    => 'crdate',
    'cruser_id' => 'cruser_id',
    'sortby' => 'sorting',
    'delete' => 'deleted',
    'enablecolumns' => array (
        'disabled' => 'hidden',
    ),
    'dynamicConfigFile' => t3lib_extMgm::extPath($_EXTKEY).'tca.php',
    'iconfile'          => t3lib_extMgm::extRelPath($_EXTKEY).'icon_tx_gallery_items.gif',
),
"feInterface" => array (
    "fe_admin_fieldList" => "hidden, oid, filename, category, videoembedcode, caption, linkpid, categoryId",
)
);

$TCA["tx_gallery_categories"] = array (
"ctrl" => array (
    'title'     => 'LLL:EXT:gc_gallery/locallang_db.xml:tx_gallery_items',
    'label'     => 'categoryTitle',
    'tstamp'    => 'tstamp',
    'sortby' => 'sorting',
    'delete' => 'deleted',
    // 'enablecolumns' => array (
        // 'disabled' => 'hidden',
    // ),
    'dynamicConfigFile' => t3lib_extMgm::extPath($_EXTKEY).'tca.php',
    'iconfile'          => t3lib_extMgm::extRelPath($_EXTKEY).'icon_tx_gallery_items.gif',
),
// "feInterface" => array (
    // "fe_admin_fieldList" => "uid, pid, categoryTitle, categoryDescription, tstamp, sorting, deleted, hidden, categorySlug",
// )
);

所以我的问题是(我认为)如何从用户正在编辑的当前图像中获取uid并将其保存到另一个表中。

这是我对TCA的第一次尝试,我对这一切是如何连接感到非常困惑。 我希望有人比我更了解这个:) 感谢。

1 个答案:

答案 0 :(得分:2)

在tcemain组件中实现了钩子概念。有一个名为processDatamap_postProcessFieldArray,当在后端保存任何记录时会调用它。因此,您可以检查它是否是您的"并做你的其他疑问或任何想要改变的事情。

an example如何使用此功能。虽然它已经很老了,但它仍然应该以这种方式工作。