菜单

How I can render Content Object from tt_content

2015年02月12日 - extensions

In Extbase extensions $this->cObj is no more available in the current scope, so you need to get it firts before you can use:
In controller

/**
     * @param $pageUid
     * @param int $colPos
     * @return string
     */
    private function getTTContent($pageUid, $colPos = 0)
    {
        $contentObj = GeneralUtility::makeInstance(\TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer::class);
        $conf['table'] = 'tt_content';
        $conf['select.'] = array(
            'pidInList' => $pageUid,
            'where' => 'colPos=' . $colPos
        );
        return $contentObj->cObjGetSingle('CONTENT', $conf);
        /*$tt_contents = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('uid', 'tt_content', 'deleted=0 and hidden=0 and pid=' . $pageUid . ' and colPos=' . $colPos . ' and sys_language_uid=' . $GLOBALS['TSFE']->tmpl->setup['config.']['sys_language_uid'], '', 'sorting asc');
        if (!empty($tt_contents)) {
            $contentObj = GeneralUtility::makeInstance(\TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer::class);
            foreach ($tt_contents as $tt_content) {
                $conf['tables'] = 'tt_content';
                $conf['source'] = $tt_content['uid'];
                $tempContent .= $contentObj->cObjGetSingle('RECORDS', $conf);
            }
        }
        return $tempContent;*/
    }

 

$cObj = $this->configurationManager->getContentObject();
$ttContentConfig = array(
    'tables'       => 'tt_content',
    'source'       => 123,
    'dontCheckPid' => 1
);
$content .= $cObj->RECORDS($ttContentConfig);

In model.

/*
	 * get TT content
	 */
	public function getTTcontent($uids){
		$content = '';
		$tempArray = explode(",", $uids);
		$cObj = $GLOBALS['TSFE']->cObj;
		foreach($tempArray as $uid){
			$ttContentConfig = array(
				'tables'       => 'tt_content',
				'source'       => $uid,
				'dontCheckPid' => 1
			);
			$content .= $cObj->RECORDS($ttContentConfig);
		}
		return $content;
	}

发表评论

电子邮件地址不会被公开。 必填项已用*标注