Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typo3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Typo3 系统类别的正确对象评估器是什么_Typo3 - Fatal编程技术网

Typo3 系统类别的正确对象评估器是什么

Typo3 系统类别的正确对象评估器是什么,typo3,Typo3,我想从我的对象中访问第一个(也是唯一一个)类别的标题。 请参阅附加的屏幕 我应该使用哪个对象评估器?因为ObjectStorages没有数字索引,所以我创建了自己的viewhelper(在DCE扩展中)以使ObjectStorages数组成为数字。它还返回给定的索引 示例:{spareparts.0.categories->dce:arrayGetIndex(索引:1)} 这将返回第二个类别。默认值为索引:0,它返回第一项 这种方法比使用f:for循环和iterator.isFirst要好。如果

我想从我的对象中访问第一个(也是唯一一个)类别的标题。 请参阅附加的屏幕


我应该使用哪个对象评估器?

因为ObjectStorages没有数字索引,所以我创建了自己的viewhelper(在DCE扩展中)以使ObjectStorages数组成为数字。它还返回给定的索引

示例:
{spareparts.0.categories->dce:arrayGetIndex(索引:1)}

这将返回第二个类别。默认值为索引:0,它返回第一项

这种方法比使用
f:for
循环和
iterator.isFirst
要好。如果查询结果中有许多类别,这可能会成为性能问题

此viewhelper的代码非常简单:

<?php
namespace ArminVieweg\Dce\ViewHelpers;

/*  | This extension is made for TYPO3 CMS and is licensed
 *  | under GNU General Public License.
 *  |
 *  | (c) 2012-2017 Armin Ruediger Vieweg <armin@v.ieweg.de>
 */

/**
 * Returns the given index of an array.
 *
 * @package ArminVieweg\Dce
 */
class ArrayGetIndexViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper
{
    /**
     * Returns the value of the given index in the given array. To make sure the indexes are numeric the array will be
     * converted. Named array keys will be overwritten by ascending index numbers (starting with 0).
     *
     * @param array $subject The array to get the value of
     * @param int|string $index Index of array. May be int or string. Default is zero (0).
     * @return mixed The value of the given array index
     */
    public function render(array $subject = null, $index = 0)
    {
        if ($subject === null) {
            $subject = $this->renderChildren();
        }
        $subject = array_values($subject);
        return $subject[$index];
    }
}