TYPO3 TCA类型是否在FLUID中选择? [英] TYPO3 TCA type select in FLUID?

查看:115
本文介绍了TYPO3 TCA类型是否在FLUID中选择?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将TCA类型用于T3后端,方法是在renderType = selectMultipleSideBySide中选择

I use for the T3 Backend a TCA type select in a renderType = selectMultipleSideBySide

以下是TCA代码:

'features' => array(
    'label' => 'Zusatz',
    'config' => array(
        'type' => 'select',
        'renderType' => 'selectMultipleSideBySide',
        'size' => 10,
        'minitems' => 0,
        'maxitems' => 999,
        'items' => array(
            array(
                'Parkplätze',
                'parking'
            ),
            array(
                'Freies Wlan',
                'wlan'
            ),
        )
    )
),

它在后端工作正常!

但是,我现在如何正确读取数据? 我现在没有正确的域/模型方法.

But, how can I read the data properly now? I dont now the right way for the Domain/Model.

/**
 * Features
 *
 * @var string
 */
protected $features = '';

/**
 * Returns the features
 *
 * @return string $features
 */
public function getFeatures() {
    return $this->features;
}

/**
 * Sets the features
 *
 * @param string $features
 * @return void
 */
public function setFeatures($features) {
    $this->features = $features;
}

发布的调试代码:features => 'parking,wlan' (12 chars)

a:

<f:for each="{newsItem.features}" as="featuresItem">
    {featuresItem}<br />
</f:for>

感谢帮助!

推荐答案

您需要用逗号将字符串爆炸,因此您可以在循环中对其进行迭代,至少有两种方法:一种是自定义ViewHelper ,第二个(描述如下)是模型中的 transient 字段,当您获得要素ID时,还需要将其翻译"为人类可读的标签. ..

You need to explode the string by comma, so you'll be able to iterate them in the loop, there are at least two approaches: one is custom ViewHelper, second (described bellow) is transient field in your model, when you'll get the IDs of features, you need also to "translate" it to human readable label...

在具有特征的模型中,像下面的示例一样,在瞬变域中添加 getter:(当然,您可以在批注中删除这些无聊的注释,但是您必须以保持@var行的正确类型!):

In your model that holds the features, add the transient field with getter like in the sample below: (of course you may delete these boring comment in the annotation but you must to keep the @var line with proper type!):

/**
 * This is a transient field, that means, that it havent
 * a declaration in SQL and TCA, but allows to add the getter,
 * which will do some special jobs... ie. will explode the comma
 * separated string to the array
 *
 * @var array
 */
protected $featuresDecoded;

/**
 * And this is getter of transient field, setter is not needed in this case
 * It just returns the array of IDs divided by comma
 *
 * @return array
 */
public function getFeaturesDecoded() {
    return \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $this->features, true);
}

如前所述,即使您没有构建多语言页面翻译文件也非常有用,您仍需要获取ID的可读标签,只需在文件typo3conf/ext/yourext/Resources/Private/Language/locallang.xlf中为您拥有的每个功能添加项您的TCA选择:

As mentioned before, you need to get human readable labels for the ID, even if you don't build multi-lingual page translation file are very useful, just in the file typo3conf/ext/yourext/Resources/Private/Language/locallang.xlf add items for each feature you have in your TCA select:

<trans-unit id="features.parking">
    <source>Parkplätze</source>
</trans-unit>
<trans-unit id="features.wlan">
    <source>Freies Wlan</source>
</trans-unit>

如您所见,点后的反式单位ID与TCA中要素的键相同,

as you can see id's of the trans-units after the dot are the same as the keys of your features from TCA,

最后,您在视图中使用此功能所需要的只是迭代 transient 字段,而不是原始字段:

finally all you need to use this in the view is iterating the transient field instead of original one:

<f:for each="{newsItem.featuresDecoded}" as="feature">
    <li>
        Feature with key <b>{feature}</b>
        it's <b>{f:translate(key: 'features.{feature}')}</b>
    </li>
</f:for>

在模型中添加新字段(即使它们是瞬时的)并添加或更改本地化文件中的条目之后,您需要清除6.2+中的系统缓存!.此选项在安装中可用工具(但您可以通过UserTS在 flash图标下将其设置为可用).

After adding new fields into model (even if they're transient) and adding or changing entries in localization files you need to clear the System cache! in 6.2+ this option is available in the install tool (but you can set it available via UserTS under the flash icon).

注意:使用自定义ViewHelper可以完成几乎相同的操作,但是IMHO瞬态字段更容易.

Note: the pretty same thing can be done with custom ViewHelper, but IMHO transient field is easier.

这篇关于TYPO3 TCA类型是否在FLUID中选择?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆