2012-02-02 84 views
2

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

$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; 
    } 

} 

能有人给我指教一下可能是错的吗?

回答

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。因为我使用的表格不会显示在后端,所以我没有一个(或者太简约)。

3

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

已经struggeld在多个项目的问题,我现在用下面的调试程序具有扩展名建设者

  • 从表中相关的类从Typo脚本删除自己添加和制作精良的项目。如果你已经在Configuration/ExtensionBuilder/settings.yaml中更改它们的状态来合并或保留,则必须对ext_tables.php,ext_tables.sql,Configuration/TCA和Configuration/Typoscript中的所有文件执行此操作。

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

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

  • 向extbase团队报告您的内容并将其添加到此线程(因为它是第一次谷歌搜索当你遇到错误)

+0

感谢您的回答 – pduersteler 2012-04-13 21:39:04