使用 TypoScript 在 PHP 中呈现内容
我需要在 PHP 中构建一个 Typoscript 文件,然后执行该脚本来获取给定页面的内容。 这是我的代码:
if (!defined('PATH_typo3conf')) die ('Could not access this script directly!');
class ContentHandler extends tslib_cObj
{
var $conf;
public function __construct()
{
tslib_eidtools::connectDB();
}
public function main()
{
$this->createConf(16);
$code = $this->cObjGet($this->conf);
echo "<pre>";
print_r($this->conf);
echo "</pre>";
echo "<pre>";
echo "code: " . $code;
echo "</pre>";
}
protected function createConf($pid)
{
$this->conf = array(
'foo' => 'CONTENT',
'foo.' => array(
'table' => 'tt_content',
'select.' => array(
'pidInList' => $pid,
'languageField' => 0,
),
'renderObj' => 'COA',
'renderObj.' => array(
'stdWrap.' => array(
'wrap' => '<b>|</b>',
),
'10' => 'TEXT',
'10.' => array(
'field' => 'header',
'wrap' => '<h3>|</h3>',
),
'20' => 'TEXT',
'20.' => array(
'field' => 'bodytext',
'wrap' => '<b>|</b>',
),
),
)
);
}
}
我相信拼写检查做得很好,但我没有得到任何回报。我使用简单的 mysql_query() 检查并返回内容。但我需要用打字稿来做到这一点。
任何帮助表示赞赏!
编辑:这不是实际的扩展脚本,但它位于 EXT/ 文件夹内。
I need to build a Typoscript file in PHP and then pretty much execute the script to get the content of a given page.
This is my Code:
if (!defined('PATH_typo3conf')) die ('Could not access this script directly!');
class ContentHandler extends tslib_cObj
{
var $conf;
public function __construct()
{
tslib_eidtools::connectDB();
}
public function main()
{
$this->createConf(16);
$code = $this->cObjGet($this->conf);
echo "<pre>";
print_r($this->conf);
echo "</pre>";
echo "<pre>";
echo "code: " . $code;
echo "</pre>";
}
protected function createConf($pid)
{
$this->conf = array(
'foo' => 'CONTENT',
'foo.' => array(
'table' => 'tt_content',
'select.' => array(
'pidInList' => $pid,
'languageField' => 0,
),
'renderObj' => 'COA',
'renderObj.' => array(
'stdWrap.' => array(
'wrap' => '<b>|</b>',
),
'10' => 'TEXT',
'10.' => array(
'field' => 'header',
'wrap' => '<h3>|</h3>',
),
'20' => 'TEXT',
'20.' => array(
'field' => 'bodytext',
'wrap' => '<b>|</b>',
),
),
)
);
}
}
I believe the typosript is built well, but I don't get anything back. I check with a simple mysql_query() and it returns content. But I need to do this with typoscript.
Any help appreciated!
Edit: This not an actual extension script, but it's inside the EXT/ folder.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的 TypoScript 不正确。查看 API (http://api.typo3.org/typo3v4/current/html/classtslib__c_obj.html#ab70d69a447f24f7416a85e7de1cb4ffb)。您必须定义数字键“10”,而不是“foo”。
应该做这项工作。
顺便提一句。:
您需要 tslib_eidtools::connectDB();仅当您使用 eID 脚本时。
Your TypoScript is not correct. Have a look at the API (http://api.typo3.org/typo3v4/current/html/classtslib__c_obj.html#ab70d69a447f24f7416a85e7de1cb4ffb). Instead of "foo" you have to define an numerical key "10".
should do the job.
Btw.:
You need tslib_eidtools::connectDB(); only, if you are using an eID Script.