我正在使用TYPO3 v6.2.x. 我尝试使用v4.1.x中创建的一个扩展
但t3lib_div::makeInstance
代码在TYPO3 v6.2.x
如何重写以下代码
$this->myRepository = t3lib_div::makeInstance('Tx_newExt_Domain_Repository_myRepository');
在TYPO3 v6.2.x
中提前致谢
EDITED
添加了完整的参考文件
我的控制器位于
位置“typo3conf / ext / new_extension / Classes / Controller / TTBAnbieterController.php”
class Tx_NewExtension_Controller_TTBAnbieterController extends Tx_Extbase_MVC_Controller_ActionController {
/**
* @var Tx_NewExtension_Domain_Repository_TTBAnbieterRepository
*/
protected $tTBAnbieterRepository;
public function initializeAction() {
$this->tTBAnbieterRepository = TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('Tx_NewExtension_Domain_Repository_TTBAnbieterRepository');
$extbaseFrameworkConfiguration = Tx_Extbase_Dispatcher::getExtbaseFrameworkConfiguration();
$HeaderData = "<link rel='stylesheet' type='text/css' href='xxxxx'/>";
$this->response->addAdditionalHeaderData($HeaderData);
$this->tTBLocationsProdukteGruppenRepository->CreateSpecialSeoTitle();
}
}
我的存储库位于
位置“/ typo3conf / EXT / new_extension /类别/域/存储库/ TTBAnbieterRepository.php”
class Tx_NewExtension_Domain_Repository_TTBAnbieterRepository extends Tx_Extbase_Persistence_Repository {
public function getSelectedAnbieter($iAnbieterOfLocation)
{
$sql = "SELECT * FROM tx_NewExtension_domain_model_ttbanbieter WHERE uid = '".$iAnbieterOfLocation."' ";
$data = $GLOBALS['TYPO3_DB']->sql(TYPO3_db, $sql);
$aResults = array();
$iCount = 0;
while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($data)) {
$aResults[$iCount] = $row;
$iCount++;
}
return $aResults;
}
}
这是Controller and Repository的完整代码。
答案 0 :(得分:2)
您应该使用依赖注入让extbase为您处理依赖项的初始化。
/**
* @var \Tx_newExt_Domain_Repository_myRepository
* @inject
*/
protected $myRepository;