亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

TYPO3 v9.5.11 Extbase:將ContainerClass生成的Service

TYPO3 v9.5.11 Extbase:將ContainerClass生成的Service

PHP
胡子哥哥 2022-07-16 18:42:57
我正在嘗試將服務對象注入我的存儲庫。我在 Classes/Services 目錄下創建了不同的服務類。我還創建了一個名為 ContainerService 的類,它為每個服務類創建并實例化一個 ServiceObject。容器服務類:namespace VendorName\MyExt\Service;use VendorName\MyExt\Service\RestClientService;class ContainerService {    private $restClient;         private $otherService;    /**     * @return RestClientService     */    public function getRestClient() {        $objectManager = GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\Object\ObjectManager::class);        if ($this->restClient === null) {            $this->restClient = $objectManager->get(RestClientService::class);                    }        return $this->restClient;    }...正如我所說,我在 ContainerService 類中創建了我的 ServiceObjects。現在我想將 ContainerService 注入我的存儲庫并使用它。MyRepository 類:namespace VendorName\MyExt\Domain\Repository;use VendorName\MyExt\Service\ContainerService;class MyRepository extends Repository{        /**     * @var ContainerService     */    public $containerService;    /**     * inject the ContainerService     *          * @param ContainerService $containerService      * @return void     */    public function injectContainerService(ContainerService $containerService) {        $this->containerService = $containerService;    }    // Use Objects from The ContainerService    public function findAddress($addressId) {        $url = 'Person/getAddressbyId/'         $someData = $this->containerService->getRestClient()->sendRequest($url)    return $someData;    }在 MyController 中,我從 findAddress 函數中接收 $someData 并對其進行一些處理。但是當我調用我的頁面時,我收到以下錯誤消息:(1/2) #1278450972 TYPO3\CMS\Extbase\Reflection\Exception\UnknownClassExceptionClass ContainerService does not exist. Reflection failed.已經嘗試重新加載所有緩存并轉儲自動加載也無濟于事。沒有用 composer 安裝 TYPO3。我感謝任何建議或幫助!謝謝!
查看完整描述

1 回答

?
慕神8447489

TA貢獻1780條經驗 獲得超1個贊

實際發現了問題。在 MyRepository 類中,注釋和 TypeHint 存在問題:


namespace VendorName\MyExt\Domain\Repository;


use VendorName\MyExt\Service\ContainerService;


class MyRepository extends Repository

{    

    /**

     *** @var \VendorName\MyExt\Service\ContainerService**

     */

    public $containerService;


    /**

     * inject the ContainerService

     *     

     * @param \VendorName\MyExt\Service\ContainerService $containerService 

     * @return void

     */

    public function injectContainerService(\VendorName\MyExt\Service\ContainerService $containerService) {

        $this->containerService = $containerService;

    }


    // Use Objects from The ContainerService


    public function findAddress($addressId) {

        $url = 'Person/getAddressbyId/' 

        $someData = $this->containerService->getRestClient()->sendRequest($url)

    return $someData;

    }

現在它起作用了。


查看完整回答
反對 回復 2022-07-16
  • 1 回答
  • 0 關注
  • 107 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號