我得到了一個關於Typo3擴展(ver。4.5 LTS)編寫的(imho)小調小問題。我所嘗試的僅僅是組成一個小MVC類模式,它包含一個小的curl語句來從遠程位置檢索信息。原則上,MVC類已經實現,我只想將它們包含到我的插件擴展的主要過程中。這是我猜的工作:如何將類(例如lib)添加到給定的Typo3擴展中?
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);
}
}
我在TYPO3的編程初學者,我想有一百個隱含的問題我沒有考慮到至今(通過只是不知道如何Typo3的隱含操作)。我到目前爲止所嘗試/做過的:
- 通過在根模板中設置模板緩存來全局禁用模板緩存。
將所有新語句轉換爲makeInstance();不想這個轉播擰我所有的MVC代碼,我通過
public function getCourseInfoOutput() { return "hello world!"; //return $this->_model->getTemplateByCourseId(5); }
,導致我的下一個問題覆蓋了調用的方法$視圖 - > getCourseInfoOutput():它只是沒有在此獲得的hello world !看來,這Typo3的好歹supresses從類的返回值了擴展根類
- 當我把所有的代碼都先後進入主要方法,它的工作就好了
誰能幫我:/我承認,我完全誤解了擴展的工作原理,但是,正如我所說的,我只是想讓我的代碼在擴展中運行並簡單地返回一個值。這真的很難嗎?
問候& thx提前!
嗨!感謝您的建議。這使得我更清楚一些事情,但MVC類的第二個問題對我而言仍然不清楚。正如人們所看到的,我只想返回一個「你好世界!」並將其傳遞給$ content變量,該變量不起作用。對我來說,看起來像是在包含「外部」類或調用它們的代碼時存在壓抑。編譯器無論如何都會找到該方法,但不會將返回的值傳遞給調用的main方法。 – 2013-03-05 21:25:35
如果你使用''makeInstance'',那麼你必須堅持''TYPO3''約定,例如,使用其中一個註冊前綴:''Tx_,tx_,user_等''。如果你不想傳達TYPO3的魔法,請使用新的。確保之前有另一個類別的「include_once」。 – pgampe 2013-03-10 23:02:05