2014-04-23 29 views
0

我有一個是被稱爲成功使用extbase服務

class tx_srfeuserregister_MyHooksHandler { 
    public function registrationProcess_afterSaveCreate ($recordArray, &$invokingObj) { 
    var_dump($recordArray); //i get here 
    } 
} 

由於被註冊到sr_feuser_register/ext_localconf.php

$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['sr_feuser_register']['tx_srfeuserregister_pi1']['registrationProcess'][] = 'EXT:sr_feuser_register/hooks/class.tx_srfeuserregister_MyHooksHandler.php:&tx_srfeuserregister_MyHooksHandler'; 

在這裏做的有益的事情,並沒有掛鉤複製/粘貼代碼,我想從位於另一個分機的extbase服務調用服務方法

typo3conf/ext/my_extension/Classes/Domain/Service /Tx_MyExtension_Domain_Service_EntityFactory.php

如何將其注入到我的鉤子中,或者通過對象工廠?我嘗試了一些東西並搜索了很多,但無法弄清楚。

+0

發佈您所做的嘗試和錯誤消息。 – lorenz

回答

0

我建議你得到一個extbase對象管理器的實例,獲取你的服務並調用你的方法。類似這樣的:

/** 
    * @var Tx_Extbase_Object_ObjectManager 
    */ 
    protected $objectManager; 

    /** 
    * @var Tx_MyExt_Service_MyService 
    */ 
    protected $myService; 

    public function registrationProcess_afterSaveCreate ($recordArray, &$invokingObj) { 
     $this->initializeObjects(); 
     // Now you can use your Service. 
     $this->myService->myMethod($recordArray); 
    } 

    /** 
    * @return void 
    */ 
    public function initializeObjects() { 
     if (empty($this->objectManager)) { 
      $this->objectManager = t3lib_div::makeInstance('Tx_Extbase_Object_ObjectManager'); 
     } 
     if (empty($this->myService)) { 
      $this->myService = $this->objectManager->get('Tx_MyExt_Service_MyService'); 
     } 
    }