Extbase在数据库中存储空值

时间:2012-02-02 09:57:13

标签: typo3 extbase

我正在尝试创建一个对象,但这些值不会存储到数据库中。这是在“索引” - 动作上完成的,因为插件是通过TypoScript插入的,实际上并不创建输出。所以在调用动作时没有给出任何对象,这就是我自己创建它的原因。

$stat = new Tx_MyExt_Domain_Model_Stat;
$stat->setSubscriberId($_COOKIE['statid']);
$stat->setDomain($_SERVER['HTTP_HOST']);
$stat->setRequestUri($_SERVER['REQUEST_URI']);

$this->statRepository = t3lib_div::makeInstance('Tx_myExt_Domain_Repository_StatRepository');
$this->statRepository->add($stat);

执行var_dump($stat)会产生以下结果:

object(Tx_MyExt_Domain_Model_Stat)#191 (9) {
  ["subscriber_id":protected]=>
  string(1) "2"
  ["domain":protected]=>
  string(22) "test.localhost.example"
  ["request_uri":protected]=>
  string(26) "/testpage/index.php?id=2"
  ["uid":protected]=>
  NULL
  ["_localizedUid":protected]=>
  NULL
  ["_languageUid":protected]=>
  NULL
  ["pid":protected]=>
  NULL
  ["_isClone":"Tx_Extbase_DomainObject_AbstractDomainObject":private]=>
  bool(false)
  ["_cleanProperties":"Tx_Extbase_DomainObject_AbstractDomainObject":private]=>
  NULL
}

所以这看起来正确分配了值。但是在查看数据库时,我得到了这个:

uid    pid    subscriber_id    domain    request_uri    crdate  
13     0      0                NULL      NULL           1328176026 

存储库:

class Tx_MyExt_Domain_Repository_StatRepository extends Tx_Extbase_Persistence_Repository
{}

型号:

class Tx_MyExt_Domain_Model_Stat extends Tx_Extbase_DomainObject_AbstractEntity 
{

    /**
     * @var int
     * @dontvalidate
     */
    protected $subscriber_id = 0;

    /**
     * @var string
     * @dontvalidate
     */
    protected $domain = '';

    /**
     * @var string
     * @dontvalidate
     */
    protected $request_uri = '';



    /**
     * @param int $susbcriber_id Subscriber id
     * @return void
     */
    public function setSubscriberId($subscriber_id) 
    {
        $this->subscriber_id = $subscriber_id;
    }

    /**
     * @return int Susbcriber id
     */
    public function getSubscriberId() 
    {
        return $this->subscriber_id;
    }

    /**
     * @param string $domain Domain
     * @return void
     */
    public function setDomain($domain)
    {
        $this->domain = $domain;
    }

    /**
     * @return string Domain
     */
    public function getDomain() 
    {
        return $this->domain;
    }

    /**
     * @param string $request_uri Request URI
     * @return void
     */
    public function setRequestUri($request_uri)
    {
        $this->request_uri = $request_uri;
    }

    /**
     * @return string Request URI
     */
    public function getRequestUri() 
    {
        return $this->request_uri;
    }

}

有人可以告诉我这里可能有什么问题吗?

2 个答案:

答案 0 :(得分:8)

通过整个extbase进程进行调试。似乎在typo3/sysext/extbase/Classes/Persistence/Backend.php中,在这一行上跳过了属性:

if (!$dataMap->isPersistableProperty($propertyName) || $this->propertyValueIsLazyLoaded($propertyValue)) continue;

这是因为$dataMap->isPersistableProperty($propertyName)没有返回任何内容。调查typo3/sysext/extbase/Classes/Persistence/Mapper,有:

/**
 * Returns TRUE if the property is persistable (configured in $TCA)
 *
 * @param string $propertyName The property name
 * @return boolean TRUE if the property is persistable (configured in $TCA)
 */
public function isPersistableProperty($propertyName) {
    return isset($this->columnMaps[$propertyName]);
}

所以解决方案很简单:创建一个有效的TCA。我没有一个(或太简约),因为我使用的表不会在后端显示。

答案 1 :(得分:3)

虽然TCA配置错误可能导致问题,但可能还有其他问题。例如,当您定义唯一键并且无提示失败时,extbase不喜欢它。

对多个项目中的问题进行了讨论,我现在对使用扩展构建器制作的项目使用以下调试例程

  • 从表格相关类以及typoscript中删除您自己的附加内容。如果您已在 Configuration / ExtensionBuilder / settings.yaml 中更改其状态以进行合并或保留,则必须对ext_tables.php,ext_tables.sql,Configuration / TCA和Configuration / Typoscript中的所有文件执行此操作。

  • 检查您的应用程序现在是否保存。如果没有,请向exentension builder报告详细的错误报告。

  • 通常您的应用程序应立即保存。递归读取您所做的更改,直到找到错误。从ext_tables.sql开始(不要忘记你每次都必须删除并读取数据库),继续使用ext_tables.php,配置/ TCA / *并以Configuration / Typoscript结束(这是我个人的经验,这些命令是最快)

  • 将您的内容报告给extbase团队并将其添加到此主题中(因为这是您遇到错误时的第一个google点击)

相关问题