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;
}
}
有人能给我建议这里可能出了什么问题吗?
I am trying to create an object, but the values are not stored into the database. This is done on an "index"-action because the plugin is inserted via TypoScript and actually does not create output. So there is no object given when calling the action, that's why I am creating it by myself.
$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);
doing a var_dump($stat)
gives the following:
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
}
So this looks like the values are assigned properly. But when looking into the database, I get this:
uid pid subscriber_id domain request_uri crdate
13 0 0 NULL NULL 1328176026
Repository:
class Tx_MyExt_Domain_Repository_StatRepository extends Tx_Extbase_Persistence_Repository
{}
Model:
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;
}
}
Can someone give me advise what may be wrong here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
调试了整个extbase流程。似乎在typo3/sysext/extbase/Classes/Persistence/Backend.php中,这一行的属性被跳过:
这是因为$dataMap->isPersistableProperty($propertyName) code> 不返回任何内容。调查
typo3/sysext/extbase/Classes/Persistence/Mapper
,有:所以解决方案非常简单:创建一个有效的TCA。我没有(或者太简约),因为我正在使用的表不会显示在后端。
Debugged through the whole extbase process. It seems that in
typo3/sysext/extbase/Classes/Persistence/Backend.php
, the attributes are skipped on this line:This because
$dataMap->isPersistableProperty($propertyName)
doesn't return something. Investigating intypo3/sysext/extbase/Classes/Persistence/Mapper
, there is:So the solution is quite simple: create a valid TCA. I didn't had one (or a too minimalistic) since the table i am using is not going to be displayed in the backend.
虽然 TCA 的错误配置可能会导致该问题,但也可能存在其他问题。例如,当您定义唯一键时,extbase 不喜欢它并且会默默地失败。
在努力解决多个项目中的问题后,我现在对使用扩展构建器创建的项目使用以下调试例程
从表相关类以及打字稿中删除您自己的添加内容。如果您已将 Configuration/ExtensionBuilder/settings.yaml 中的状态更改为合并或保留,则必须对 ext_tables.php、ext_tables.sql、Configuration/TCA 和 Configuration/Typoscript 中的所有文件执行此操作。
检查您的应用程序现在是否已保存。如果没有,请向扩展构建器报告详细的错误报告。
通常您的应用程序应该立即保存。递归地读取您所做的更改,直到找到错误。从 ext_tables.sql 开始(不要忘记每次都必须删除并重新添加数据库),继续 ext_tables.php、Configuration/TCA/* 并以 Configuration/Typoscript 结束(这是我个人的经验,这些顺序是最快)
向 extbase 团队报告您的内容并将其添加到此线程(因为这是您遇到错误时第一个 google 命中)
While misconfiguration of TCA might be causing the problem, there might be others. For example, extbase does not like it when you are defining unique keys and fails silently.
Having struggeld with the problems in multiple projects, I am now using the following debugging routine for projects made with the extension builder
Remove your own additions from the table related classes and as well from typoscript. This has to be done for ext_tables.php, ext_tables.sql, all files in Configuration/TCA and Configuration/Typoscript if you have changed their state in Configuration/ExtensionBuilder/settings.yaml to merge or keep.
Check if your application now does save. If not, report a detailed bug report to exentension builder.
Normally your application should save now. Readd recursively the changes you've made until you find the error. Start with ext_tables.sql (don't forget you have to remove and readd the database every time), go on with ext_tables.php, Configuration/TCA/* and end with Configuration/Typoscript (it's my personal experience that these order is the fastest)
Report your stuff to the extbase team and add it to this thread (as it's the first google hit when you experience the error)