tt_content 个字段使用 extbase 存储库方法 TYPO3
tt_content fields using extbase repository method TYPO3
我正在尝试使用 TYPO3 extbase 存储库方法开发自定义扩展。我想在我的扩展程序中获取 tt_content "pi_flexform" 字段值。
为了实现这一点,我遵循了持久性方法。
在我这样添加的错字配置文件中;
plugin.tx_myext{
persistence {
classes {
\TYPO3\MyExt\Domain\Model\Myext {
mapping {
tableName = tt_content
recordType = \TYPO3\MyExt\Domain\Model\Myext
columns {
pi_flexform.mapOnProperty = piflexform
}
}
}
}
}
}
在我的模型文件中,我实现了以下代码;
/**
* @var string
*/
protected $piflexform;
/**
* @return the $piflexform
*/
public function getPiflexform()
{
return $this->piflexform;
}
/**
* @param string $piflexform
*/
public function setPiflexform($piflexform)
{
$this->piflexform = $piflexform;
}
并且也在存储库文件中;
$queryStmt = "SELECT pi_flexform FROM tt_content WHERE CType = 'dce_dce10' AND pid = 1 AND sys_language_uid = 0";
$query = $this->createQuery();
$query->statement( $queryStmt );
return $query->execute();
但它 returns 是一个空对象。
TYPO3\CMS\Extbase\Persistence\Generic\QueryResultprototypeobject (empty)
0 => TYPO3\VstRssfeed\Domain\Model\Vstrssfeedprototypepersistent entity (uid=0, pid=0)
piflexform => NULL
uid => 0 (integer)
_localizedUid => 0 (integer)modified
_languageUid => 0 (integer)modified
_versionedUid => 0 (integer)modified
pid => 0 (integer)
你们能帮我解决这个问题吗?提前致谢。
How to Effectively use the Repository and Query Object of Extbase?
http://blog.typoplanet.de/2010/01/27/the-repository-and-query-object-of-extbase/
这是您的存储库的示例:
myext/Classes/Domain/Repository/ContentRepository.php
<?php
namespace TYPO3\MyExt\Domain\Repository;
/**
* Class ContentRepository
* @package TYPO3\MyExt\Domain\Repository
*/
class ContentRepository extends \TYPO3\CMS\Extbase\Persistence\Repository {
/**
* Initializes the repository.
*
* @return void
*/
public function initializeObject() {
/** @var $querySettings \TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings */
$querySettings = $this->objectManager->get('TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings');
$querySettings->setRespectStoragePage(FALSE);
$this->setDefaultQuerySettings($querySettings);
}
/**
* Find By CType
*
* @param string $cType
* @param integer $pid
* @return \TYPO3\CMS\Extbase\Persistence\QueryResultInterface
*/
public function findByCtype($cType, $pid = FALSE) {
$constraints = array();
$query = $this->createQuery();
$constraints[] = $query->equals('CType', $cType);
if ($pid) {
$constraints[] = $query->equals('pid', $pid);
}
if ($constraints) {
if (count($constraints) == 1) {
$query->matching($constraints[0]);
} else {
$query->matching($query->logicalAnd($constraints));
}
}
return $query->execute();
}
}
下面是您的控制器应如何完成工作的示例:
myext/Classes/Controller/SomeController.php
class SomeController extends \TYPO3\CMS\E... {
/**
* @var \TYPO3\MyExt\Domain\Repository\ContentRepository
* @inject
*/
protected $contentRepository = NULL;
public function someAction() {
$contents = $this->contentRepository->findByCtype('dce_dce10');
if ($contents) {
foreach ($contents as $content) {
echo '<h1>'.$content->getUid().'</h1>';
echo PHP_EOL.'<br />';
echo $content->getPiflexform();
echo PHP_EOL.'<br />';
}
}
}
}
我正在尝试使用 TYPO3 extbase 存储库方法开发自定义扩展。我想在我的扩展程序中获取 tt_content "pi_flexform" 字段值。
为了实现这一点,我遵循了持久性方法。
在我这样添加的错字配置文件中;
plugin.tx_myext{
persistence {
classes {
\TYPO3\MyExt\Domain\Model\Myext {
mapping {
tableName = tt_content
recordType = \TYPO3\MyExt\Domain\Model\Myext
columns {
pi_flexform.mapOnProperty = piflexform
}
}
}
}
}
}
在我的模型文件中,我实现了以下代码;
/**
* @var string
*/
protected $piflexform;
/**
* @return the $piflexform
*/
public function getPiflexform()
{
return $this->piflexform;
}
/**
* @param string $piflexform
*/
public function setPiflexform($piflexform)
{
$this->piflexform = $piflexform;
}
并且也在存储库文件中;
$queryStmt = "SELECT pi_flexform FROM tt_content WHERE CType = 'dce_dce10' AND pid = 1 AND sys_language_uid = 0";
$query = $this->createQuery();
$query->statement( $queryStmt );
return $query->execute();
但它 returns 是一个空对象。
TYPO3\CMS\Extbase\Persistence\Generic\QueryResultprototypeobject (empty)
0 => TYPO3\VstRssfeed\Domain\Model\Vstrssfeedprototypepersistent entity (uid=0, pid=0)
piflexform => NULL
uid => 0 (integer)
_localizedUid => 0 (integer)modified
_languageUid => 0 (integer)modified
_versionedUid => 0 (integer)modified
pid => 0 (integer)
你们能帮我解决这个问题吗?提前致谢。
How to Effectively use the Repository and Query Object of Extbase?
http://blog.typoplanet.de/2010/01/27/the-repository-and-query-object-of-extbase/
这是您的存储库的示例:
myext/Classes/Domain/Repository/ContentRepository.php
<?php
namespace TYPO3\MyExt\Domain\Repository;
/**
* Class ContentRepository
* @package TYPO3\MyExt\Domain\Repository
*/
class ContentRepository extends \TYPO3\CMS\Extbase\Persistence\Repository {
/**
* Initializes the repository.
*
* @return void
*/
public function initializeObject() {
/** @var $querySettings \TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings */
$querySettings = $this->objectManager->get('TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings');
$querySettings->setRespectStoragePage(FALSE);
$this->setDefaultQuerySettings($querySettings);
}
/**
* Find By CType
*
* @param string $cType
* @param integer $pid
* @return \TYPO3\CMS\Extbase\Persistence\QueryResultInterface
*/
public function findByCtype($cType, $pid = FALSE) {
$constraints = array();
$query = $this->createQuery();
$constraints[] = $query->equals('CType', $cType);
if ($pid) {
$constraints[] = $query->equals('pid', $pid);
}
if ($constraints) {
if (count($constraints) == 1) {
$query->matching($constraints[0]);
} else {
$query->matching($query->logicalAnd($constraints));
}
}
return $query->execute();
}
}
下面是您的控制器应如何完成工作的示例:
myext/Classes/Controller/SomeController.php
class SomeController extends \TYPO3\CMS\E... {
/**
* @var \TYPO3\MyExt\Domain\Repository\ContentRepository
* @inject
*/
protected $contentRepository = NULL;
public function someAction() {
$contents = $this->contentRepository->findByCtype('dce_dce10');
if ($contents) {
foreach ($contents as $content) {
echo '<h1>'.$content->getUid().'</h1>';
echo PHP_EOL.'<br />';
echo $content->getPiflexform();
echo PHP_EOL.'<br />';
}
}
}
}