Debugging 如何将类(例如lib)添加到给定的Typo3扩展?
我有一个(imho)关于打字3扩展(4.5版LTS)的小问题。我尝试的只是构建一个小的MVC类模式,其中包含一个小的curl语句,用于从远程位置检索信息。原则上,MVC类已经实现了,我只想将它们包含在插件扩展的主过程中。这就是我猜想的结果:Debugging 如何将类(例如lib)添加到给定的Typo3扩展?,debugging,extension-methods,typo3,Debugging,Extension Methods,Typo3,我有一个(imho)关于打字3扩展(4.5版LTS)的小问题。我尝试的只是构建一个小的MVC类模式,其中包含一个小的curl语句,用于从远程位置检索信息。原则上,MVC类已经实现了,我只想将它们包含在插件扩展的主过程中。这就是我猜想的结果: class tx_uniklstudgangext2013_pi1 extends tslib_pibase { public $prefixId = 'tx_uniklstudgangext2013_pi1'; // Same as c
class tx_uniklstudgangext2013_pi1 extends tslib_pibase {
public $prefixId = 'tx_uniklstudgangext2013_pi1'; // Same as class name
public $scriptRelPath = 'pi1/class.tx_uniklstudgangext2013_pi1.php'; // Path to this script relative to the extension dir.
public $extKey = 'uniklstudgangext2013'; // The extension key.
public $pi_checkCHash = TRUE;
/**
* The main method of the Plugin.
*
* @param string $content The Plugin content
* @param array $conf The Plugin configuration
* @return string The content that is displayed on the website
*/
public function main($content, array $conf) {
$this->conf = $conf;
$this->pi_setPiVarDefaults();
$this->pi_loadLL();
$view = t3lib_div::makeInstance('tx_uniklstudgangext2013_pi1_view');
// !HERE! : also tried with new(), since I don't want to deal with XCLASS here...
// this works: $content = "<p>Hello world!</p>";...the line below doesn't...
$content = $view->getCourseInfoOutput();
/*'
<strong>This is a few paragraphs:</strong><br />
<p>This is line 1</p>
<p>This is line 2</p>
<h3>This is a form:</h3>
<form action="' . $this->pi_getPageLink($GLOBALS['TSFE']->id) . '" method="POST">
<input type="text" name="' . $this->prefixId . '[input_field]" value="' . htmlspecialchars($this->piVars['input_field']) . '" />
<input type="submit" name="' . $this->prefixId . '[submit_button]" value="' . htmlspecialchars($this->pi_getLL('submit_button_label')) . '" />
</form>
<br />
<p>You can click here to ' . $this->pi_linkToPage('get to this page again', $GLOBALS['TSFE']->id) . '</p>
';
*/
return $this->pi_wrapInBaseClass($content);
}
}
提前问候和谢谢
$content
是任何HTML字符串。如果您使用kickstarter创建了扩展,或者将任何现有扩展用作样板文件,那么您只需要关心函数内部发生的事情。
这完全取决于你。TYPO3将创建类并调用main方法,并将返回值用作内容。
您可以在以下网址找到所有相关文档:
当然,您必须不要在函数中使用任何HTML。函数必须使用return语句以串联字符串的形式返回内容
TYPO3 CMS
使用ob_clean
刷新输出缓冲区。如果您在TYPO3 CMS
之前强制输出任何内容,那么您将破坏它。Hi!谢谢你的建议。这使一些事情对我来说更加清楚,但是MVC类的第二个问题对我来说仍然不清楚。可以看到,我只想返回一个“helloworld!”并将其传递给$content变量,该变量不起作用。对我来说,似乎对包含“外部”类或调用它们的代码有限制。编译器无论如何都会找到该方法,但不会将返回值传递给调用的主方法。如果使用makeInstance
,则必须遵守TYPO3
约定,例如使用其中一个注册前缀:Tx\u、Tx\u、user\u等
。如果你不想继续使用TYPO3魔术,就使用new吧。确保在之前包含一次另一个类。
public function getCourseInfoOutput() {
return "hello world!";
//return $this->_model->getTemplateByCourseId(5);
}