我只是使用两个自己的Model类扩展了现有的Typo3 4.7 Extension . 它运行得很好,当我尝试通过Object Accessor 访问模板中的模型类的某些SubObject时,Backendforms看起来像预期的那样我无法访问该属性 . 给我看的问题是,对象存储中的属性对象“mainColor”是一个HashCode,它包含我想要访问的实际对象(哈希码后面的对象是数据库中正确的相关对象) .
你们中有谁有想法可能存在的问题吗?
如果需要更多代码片段,我将提供它们 . 但由于我真的不知道问题的来源,我宁愿不提供一堵代码墙 .
域/型号/ Cluster.php
/**
* Main Color of Cluster
* @var Tx_Extbase_Persistence_ObjectStorage<Tx_Alp_Domain_Model_ColorCombination> $mainColor
*/
protected $mainColor;
/**
* Subcolors of Cluster
* @var Tx_Extbase_Persistence_ObjectStorage<Tx_Alp_Domain_Model_ColorCombination> $subColors
*/
protected $subColors;
/**
* Constructor
* @return void
*/
public function __construct() {
$this->initStorageObjects();
}
/**
* Initializes all Tx_Extbase_Persistence_ObjectStorage properties.
* @return void
*/
protected function initStorageObjects() {
$this->subColors = new Tx_Extbase_Persistence_ObjectStorage();
$this->mainColor = new Tx_Extbase_Persistence_ObjectStorage();
}
TCA / Cluster.php
'sub_colors' => array(
'exclude' => 1,
'label' => 'Sub-Colors',
'config' => array(
// edited
'type' => 'inline',
'internal_type' => 'db',
'allowed' => 'tx_alp_domain_model_colorcombination',
'foreign_table' => 'tx_alp_domain_model_colorcombination',
'MM' => 'tx_alp_cluster_subcolorcombination_mm',
'MM_opposite_field' => 'parent_cluster',
'size' => 6,
'autoSizeMax' => 30,
'maxitems' => 9999,
'multiple' => 0,
'selectedListStyle' => 'width:250px;',
'wizards' => array(
'_PADDING' => 5,
'_VERTICAL' => 1,
'suggest' => array(
'type' => 'suggest',
),
),
),
),
流体调试输出可在此处找到:
http://i60.tinypic.com/28kluub.jpg
感谢您的帮助:(抱歉我的英语不好,这是我的第一个问题,希望我做得对;)
1 回答
除非从模型到子模型之间存在1:1关系,否则无法访问子模型,因为子模型是ObjectStorage .
例:
Domain/Model/Cluster.php
这意味着Cluster模型具有一种主要颜色(注意注释),这是一个1:1的关系 .
因此使用
{cluster.mainColor.property}
将起作用 .你在做什么是:
Domain/Model/Cluster.php
这意味着每个群集可以有多种主要颜色,这是1:n关系 . 因此,您必须遍历mainColors(并调用属性$ mainColors):