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中的每个第n个列表元素之后添加扩展中的PHP代码_Php_Typo3 - Fatal编程技术网

在TYPO3中的每个第n个列表元素之后添加扩展中的PHP代码

在TYPO3中的每个第n个列表元素之后添加扩展中的PHP代码,php,typo3,Php,Typo3,我正在使用老式方式(kickstarter)在TYPO3中构建扩展。我想在列表的第三个元素之后添加一些PHP代码,但我真的不知道怎么做 我的代码如下所示: protected function makeList($res) { $items = array(); // Make list table rows while (($this->internal['currentRow'] = $GLOBALS['TYPO3_DB']->sql_fetch_

我正在使用老式方式(kickstarter)在TYPO3中构建扩展。我想在列表的第三个元素之后添加一些PHP代码,但我真的不知道怎么做

我的代码如下所示:

protected function makeList($res) {
    $items = array();
        // Make list table rows
    while (($this->internal['currentRow'] = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) !== FALSE) {
        $items[] = $this->makeListItem();
    }

    $out = '<div' . $this->pi_classParam('listrow') . '>list items</div>';
    return $out;
}

如果我理解正确,您将需要以下内容:

protected function makeList($res) {
    $items = array();
    // Make list table rows
    $i = 0;
    $out = '<div' . $this->pi_classParam('listrow') . '>';
    while (($this->internal['currentRow'] = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) !== FALSE) {

        $out .= $this->makeListItem();
        $i++;
        if ($i == 3) {
             $out .= '<img src="whateverjpg">';
             $i = 0; // if you want to do it every 3 images
        }            
    }


    $out .= '</div>';
    return $out;
}
受保护函数生成列表($res){
$items=array();
//生成列表表行
$i=0;
$out='';
而($this->internal['currentRow']=$GLOBALS['TYPO3\u DB']->sql\u fetch\u assoc($res))!==FALSE){
$out.=$this->makeListItem();
$i++;
如果($i==3){
$out.='';
$i=0;//如果要每3张图像执行一次
}            
}
$out.='';
退回$out;
}

此代码将
php代码插入页面顶部(源代码之前),如果您想要打印类似html的内容,最好将此逻辑添加到视图中(因为它看起来像是视图逻辑)。实际上,您可以将所有逻辑移到视图中,并将$items传递给视图。也许我不太明白你想要实现什么,所以如果你给我更多的信息,我可能会更好地帮助你。:)元素的扩展生成列表,我想在第n个列表项之后插入图像。正如我所说的,如果将$items数组传递给视图,并在视图上执行此操作,效果会更好。尽管如此,我还是编辑了代码来做我认为您想要做的事情。这段代码将在div“listrow”中创建一个列表,并且每3项它将添加一个图像,只要makeListItem创建列表的项。
protected function makeList($res) {
    $items = array();
    // Make list table rows
    $i = 0;
    $out = '<div' . $this->pi_classParam('listrow') . '>';
    while (($this->internal['currentRow'] = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) !== FALSE) {

        $out .= $this->makeListItem();
        $i++;
        if ($i == 3) {
             $out .= '<img src="whateverjpg">';
             $i = 0; // if you want to do it every 3 images
        }            
    }


    $out .= '</div>';
    return $out;
}