TYPO3存储库查询返回uid和pid,但没有其他字段

时间:2016-06-20 11:52:31

标签: typo3 extbase

我正在对拼写错误3任务中的一个非常简单的表进行查询。但是,仅返回字段“uid”和“pid”,其他字段为NULL

我的实体:

<?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' => [],
];

这是来自查询等工作的另一个表

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

1 个答案:

答案 0 :(得分: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;
    }
}

?>