2016-06-20 52 views
0

我在排字3任務中的一個非常簡單的表上查詢。但是,只返回字段「uid」和「pid」,其他字段爲NULLTYPO3存儲庫查詢返回uid和pid,但沒有其他字段

我的實體:

<?php 
namespace Name\SampleExtension\Domain\Model; 

use TYPO3\CMS\Extbase\DomainObject\AbstractEntity; 

class MailAgent extends AbstractEntity 
{ 

    /** 
    * @var integer 
    */ 
    protected $uid; 

    /** 
    * @var string 
    */ 
    protected $customeremail; 

    /** 
    * @var string 
    */ 
    protected $searchparameters; 

    /** 
    * @var string 
    */ 
    protected $resultlist; 


    public function getUid() 
    { 
     return $this->uid; 
    } 

    public function setCustomerEmail($customeremail) 
    { 
     $this->customeremail = $customeremail; 
    } 
    public function getCustomerEmail() 
    { 
     return $this->customeremail; 
    } 

    public function setSearchParameters($searchparameters) 
    { 
     $this->searchparameters = $searchparameters; 
    } 
    public function getSearchParameters() 
    { 
     return $this->searchparameters; 
    } 

    public function setResultList($resultlist) 
    { 
     $this->resultlist = $resultlist; 
    } 
    public function getResultList() 
    { 
     return $this->resultlist; 
    } 
} 

?> 

資源庫:

<?php 

namespace Name\SampleExtension\Domain\Repository; 

use TYPO3\CMS\Extbase\Persistence\Repository; 

class MailAgentRepository extends Repository 
{ 

    public function findByUids($uids) 
    { 
     $query = $this->createQuery(); 
     foreach ($uids as $uid) { 
      $constraints[] = $query->equals('uid', $uid); 
     } 

     return $query->matching(
      $query->logicalOr(
       $constraints 
      ) 
     )->execute(); 
    } 
} 

?> 

和查詢裏面的任務:

<?php 

namespace Name\SampleExtension\Task; 

use TYPO3\CMS\Scheduler\Task\AbstractTask; 
use TYPO3\CMS\Extbase\Object\ObjectManager; 
use TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager; 
use Name\SampleExtension\Domain\Model\MailAgent; 
use Name\SampleExtension\Domain\Repository\MailAgentRepository; 

class MailAgentCheckup extends AbstractTask 
{ 
    public function execute() { 

     $objectManager    = GeneralUtility::makeInstance(ObjectManager::class); 
     $this->MailAgentRepository = $objectManager->get(MailAgentRepository::class); 
     $query = $this->MailAgentRepository->createQuery(); 

     $allCustomers = $this->MailAgentRepository->findAll(); 

     foreach ($allCustomers as $customer) { 
      var_dump($customer); 
     } 

     return true; 
    } 
} 

?> 

我不知道爲什麼不返回其他領域,但是uid和pid都是。我的猜測是我需要在其他地方聲明映射。

編輯:我的TCA的內容,這可能是錯誤的或不夠,但因爲我正在對現有的擴展工作,我從TCA的工作表複製。

tx_sampleextension_domain_model_mailagent.php

return [ 
    'columns' => [ 
     'uid' => [], 
     'customer_email' => [], 
     'search_parameters' => [], 
     'result_list' => [], 
    ], 
    'types' => [], 
]; 

這是從哪個querys等其他工作表中

return [ 
    'columns' => [ 
     'immovable' => [], 
     'type' => [], 
     'title' => [], 
     'path' => [], 
     'mark_to_delete' => [], 
    ], 
]; 
+0

請問你的文件'''Configuration/TCA/MailAgent.php'''看起來像? –

+0

另外,建議使用一個'CommandController'來定義任務,它給你一個完全初始化的extbase環境。它仍然可以使用調度程序執行,並且實現起來要容易得多。 – Jost

+0

你是如何創建這些字段的?列是否存在並且是否在表中相應地配置?接下來,正如傑伊所說,檢查你的TCA的這些領域。最重要的是,完全刷新緩存或手動刪除緩存的TCA。 – j4k3

回答

0

給一個嘗試注入你的資料庫

<?php 

namespace Name\SampleExtension\Task; 

use TYPO3\CMS\Scheduler\Task\AbstractTask; 
use TYPO3\CMS\Extbase\Object\ObjectManager; 
use TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager; 
use Name\SampleExtension\Domain\Model\MailAgent; 
use Name\SampleExtension\Domain\Repository\MailAgentRepository; 

use TYPO3\CMS\Extbase\Utility\DebuggerUtility; 

class MailAgentCheckup extends AbstractTask 
{ 
    /** 
    * mailAgentRepository 
    * 
    * @var \Name\SampleExtension\Domain\Repository\MailAgentRepository 
    * @inject 
    */ 
    protected $mailAgentRepository = NULL; 

    public function injectMailAgentRepository(\Name\SampleExtension\Domain\Repository\MailAgentRepository $mailAgentRepository) { 
     $this->mailAgentRepository = $mailAgentRepository; 
    } 

    public function execute() { 

     $allCustomers = $this->mailAgentRepository->findAll(); 
     DebuggerUtility::var_dump($allCustomers);exit; 

     // OR 

     $arguments = $this->request->getArguments(); 

     $uid = $arguments['uid']; 
     $singleCustomer = $this->mailAgentRepository->findByUid(intval($uid)); 
     DebuggerUtility::var_dump($singleCustomer);exit; 

     /*foreach ($allCustomers as $customer) { 
      var_dump($customer); 
     }*/ 

     return true; 
    } 
} 

?> 
+0

我不覺得這是正確的路要走嗎?我甚至沒有請求對象,因爲我在任務中而不是控制器中工作。 – Stuffy

+0

哦,我看你沒有控制器。那麼可能會很好地創建存儲庫實例,如下所示:$ mailAgentRepository = GeneralUtility :: makeInstance('Name \\ SampleExtension \\ Domain \\ Repository \\ MailAgentRepository');和$ mailAgentRepository-> findAll();等等 –

相關問題