问题描述
我需要在 PHP 中构建一个 Typoscript 文件,然后几乎执行该脚本以获取给定页面的内容.这是我的代码:
if (!defined('PATH_typo3conf')) die ('无法直接访问这个脚本!');类 ContentHandler 扩展了 tslib_cObj{变量 $conf;公共函数 __construct(){tslib_eidtools::connectDB();}公共函数 main(){$this->createConf(16);$code = $this->cObjGet($this->conf);echo "";print_r($this->conf);echo "</pre>";echo "";回声代码:".$代码;echo "</pre>";}受保护的函数 createConf($pid){$this->conf = 数组('富' =>'内容','foo.'=>大批('表' =>'tt_content','选择.'=>大批('pidInList' =>$pid,'语言字段' =>0,),'renderObj' =>'COA','renderObj.'=>大批('标准包装.'=>大批('包裹' =>'<b>|</b>',),'10' =>'文本',10."=>大批('字段' =>'标题','包裹' =>'<h3>|</h3>',),'20' =>'文本',20."=>大批('字段' =>'文章主体','包裹' =>'<b>|</b>',),),));}}
我相信错别字写得很好,但我没有得到任何回报.我检查了一个简单的 mysql_query() 并返回内容.但我需要用打字稿来做到这一点.
感谢任何帮助!
这不是一个实际的扩展脚本,但它在 EXT/文件夹内.
您的 TypoScript 不正确.看看 API (http://api.typo3.org/typo3v4/current/html/classtslib__c_obj.html#ab70d69a447f24f7416a85e7de1cb4ffb).您必须定义一个数字键10",而不是foo".
$this->conf = array('富' =>'内容','foo.'=>大批(
应该完成这项工作.
顺便说一句:你需要 tslib_eidtools::connectDB();仅当您使用 eID 脚本时.
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.
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".
$this->conf = array(
'foo' => 'CONTENT',
'foo.' => array(
should do the job.
Btw.: You need tslib_eidtools::connectDB(); only, if you are using an eID Script.
这篇关于使用 TypoScript 在 PHP 中呈现内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!