在 Extbase 中使用 tt_content 中的图像内容对象

发布于 2024-11-29 00:17:44 字数 2037 浏览 2 评论 0原文

我想编写一个 Extbase 后端模块,它需要从 tt_content 生成的所有对象的列表,其中 CType = 'image'。

现在我开始定义一个简单的模型

class Tx_Myextension_Domain_Model_Content extends Tx_Extbase_DomainObject_AbstractEntity
{

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

    /**
     * @return the $header
     */
    public function getHeader()
    {
        return $this->header;
    }

    /**
     * @param string $header
     */
    public function setHeader($header)
    {
        $this->header = $header;
    }

}

和一个存储库

class Tx_Myextension_Domain_Repository_ContentRepository extends Tx_Extbase_Persistence_Repository
{

    public function initializeObject()
    {
        $querySettings = $this->objectManager->create('Tx_Extbase_Persistence_Typo3QuerySettings');
        $querySettings->setRespectStoragePage(FALSE);
        $this->setDefaultQuerySettings($querySettings);
    }
}

据我所知,initializeObject 方法是一种获取所有内容元素的方法,无论它们有哪个 pid。

最后,我尝试将我的内容类映射到 tt_content:

plugin.tx_myextension {
  persistence {
    classes {
      Tx_Myextension_Domain_Model_Content {
        mapping {
          tableName = tt_content
          recordType = Tx_Myextension_Domain_Model_Content
          columns {
            header.mapOnProperty = header
          }
        }
      }
    }
  }
}

module.tx_myextension {
    persistence < plugin.tx_myextension.persistence
}

不,我想使用存储库。例如,countAll。不幸的是它总是返回 0。查找 MySQL 查询会发现问题:

SELECT COUNT(*) 
FROM tt_content  
WHERE (tt_content.CType='Tx_Myextension_Domain_Model_Content') 
  AND tt_content.deleted=0 AND tt_content.hidden=0 
  AND (tt_content.starttime<=1313073660) 
  AND (tt_content.endtime=0 OR tt_content.endtime>1313073660) 
  AND tt_content.sys_language_uid IN (0,-1) 
  AND tt_content.pid IN (0)

Typo 3 或 Extbase 或不同的东西将所有这些 where 子句添加到查询中。我只是想摆脱 CType 和 pid 子句。正如我所说,我认为Repo中使用的方法会导致忽略pid,但事实显然并非如此。

有人可以帮助我吗?我想要的只是图像内容元素的数组。先感谢您。

I want to write an Extbase Backend module which needs a list of all Objects generated from tt_content with CType = 'image'.

Now I started defining a simple model

class Tx_Myextension_Domain_Model_Content extends Tx_Extbase_DomainObject_AbstractEntity
{

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

    /**
     * @return the $header
     */
    public function getHeader()
    {
        return $this->header;
    }

    /**
     * @param string $header
     */
    public function setHeader($header)
    {
        $this->header = $header;
    }

}

and a Repository

class Tx_Myextension_Domain_Repository_ContentRepository extends Tx_Extbase_Persistence_Repository
{

    public function initializeObject()
    {
        $querySettings = $this->objectManager->create('Tx_Extbase_Persistence_Typo3QuerySettings');
        $querySettings->setRespectStoragePage(FALSE);
        $this->setDefaultQuerySettings($querySettings);
    }
}

As far as I know the initializeObject method is a way to get all content elements, no matter which pid they have.

At last I tried to map my Content Class on tt_content:

plugin.tx_myextension {
  persistence {
    classes {
      Tx_Myextension_Domain_Model_Content {
        mapping {
          tableName = tt_content
          recordType = Tx_Myextension_Domain_Model_Content
          columns {
            header.mapOnProperty = header
          }
        }
      }
    }
  }
}

module.tx_myextension {
    persistence < plugin.tx_myextension.persistence
}

No I want to use the Repo. e.g. countAll. Unfortunately it always returns 0. Looking for the MySQL query discovers the problem:

SELECT COUNT(*) 
FROM tt_content  
WHERE (tt_content.CType='Tx_Myextension_Domain_Model_Content') 
  AND tt_content.deleted=0 AND tt_content.hidden=0 
  AND (tt_content.starttime<=1313073660) 
  AND (tt_content.endtime=0 OR tt_content.endtime>1313073660) 
  AND tt_content.sys_language_uid IN (0,-1) 
  AND tt_content.pid IN (0)

Typo 3 or Extbase or something different added all these where clauses to the query. I just want to get rid of the CType and pid clauses. As I said, I thought that the method used in the Repo leads to ignoring the pid, which is obviously not the case.

Can somebody help me? All I want is an array of Image Content Elements. Thank you in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

逆蝶 2024-12-06 00:17:44

迟到的答复:您很可能想打电话

query->getQuerySettings()
    ->setRespectEnableFields(FALSE)
    ->setRespectSysLanguage(FALSE);

询问。您可以对存储库的 initializeObject 方法中的所有查询禁用它:

$querySettings = $this->objectManager->create('Tx_Extbase_Persistence_Typo3QuerySettings');
$querySettings
    ->setRespectStoragePage(FALSE)
    ->setRespectEnableFields(FALSE)
    ->setRespectSysLanguage(FALSE);
$this->setDefaultQuerySettings($querySettings);

请参阅:TYPO 3个API文档

Late answer: You'll most likely want to call

query->getQuerySettings()
    ->setRespectEnableFields(FALSE)
    ->setRespectSysLanguage(FALSE);

for your query. You can disable it for all queries in your repository's initializeObject method:

$querySettings = $this->objectManager->create('Tx_Extbase_Persistence_Typo3QuerySettings');
$querySettings
    ->setRespectStoragePage(FALSE)
    ->setRespectEnableFields(FALSE)
    ->setRespectSysLanguage(FALSE);
$this->setDefaultQuerySettings($querySettings);

See: TYPO 3 API docs

◇流星雨 2024-12-06 00:17:44

尝试从持久性定义中删除节点“recordType”。

Try to remove the Node "recordType" from your Persistence Definition.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文