TYPO3 Extbase 1:n视图中未显示的关系对象
我目前正在学习extbase和fluid。我阅读了这篇SO文章,以便在我的分机中建立关系。我有角色和人。N人可以有M个角色。现在后端一切正常。在前端使用f:debug时,我看不到对象。我的问题是extbase没有正确地解决这个关系(我想是吧?) 这是我的关系课:TYPO3 Extbase 1:n视图中未显示的关系对象,typo3,relation,extbase,Typo3,Relation,Extbase,我目前正在学习extbase和fluid。我阅读了这篇SO文章,以便在我的分机中建立关系。我有角色和人。N人可以有M个角色。现在后端一切正常。在前端使用f:debug时,我看不到对象。我的问题是extbase没有正确地解决这个关系(我想是吧?) 这是我的关系课: <?php namespace Vendor\People\Domain\Model; /** * Class PersonRoleRelation * @scope prototype * @entity * @pack
<?php
namespace Vendor\People\Domain\Model;
/**
* Class PersonRoleRelation
* @scope prototype
* @entity
* @package Vendor\People\Domain\Model
*/
class PersonRelation extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity {
/**
* @var \Vendor\People\Domain\Model\Person
*/
protected $person;
/**
* @var \Vendor\People\Domain\Model\Role
*/
protected $role;
/**
* @param \Vendor\People\Domain\Model\Person $person
*/
public function setPerson($person) {
$this->person = $person;
}
/**
* @return \Vendor\People\Domain\Model\Person
*/
public function getPerson() {
return $this->person;
}
/**
* @param \Vendor\People\Domain\Model\Role $role
*/
public function setRole($role) {
$this->role = $role;
}
/**
* @return \Vendor\People\Domain\Model\Role
*/
public function getRole() {
return $this->role;
}
}
TCA配置:
tx_people_domain_model_person.php:
<?php
return array(
'ctrl' => array(
'title' => 'Person',
'label' => 'firstname',
'label_alt' => ',lastname',
'label_alt_force' => TRUE,
'tstamp' => 'tstamp',
'crdate' => 'crdate',
'dividers2tabs' => TRUE,
'delete' => 'deleted',
'enablecolumns' => array(
'disabled' => 'hidden',
),
'iconfile' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extRelPath('people') . 'ext_icon.gif'
),
'types' => array(
'1' => array('showitem' => 'firstname, lastname, role, description, photo, roles')
),
'columns' => array(
'hidden' => array(
'exclude' => 1,
'label' => 'LLL:EXT:lang/locallang_general.xml:LGL.hidden',
'config' => array(
'type' => 'check'
)
),
'firstname' => array(
'exclude' => 0,
'label' => 'Vorname',
'config' => array(
'type' => 'input',
'size' => 225,
)
),
'lastname' => array(
'exclude' => 0,
'label' => 'Nachname',
'config' => array(
'type' => 'input',
'size' => 225,
)
),
'role' => array(
'exclude' => 0,
'label' => 'Rolle',
'config' => array(
'type' => 'input',
'size' => 225,
)
),
'description' => array(
'exclude' => 0,
'label' => 'Beschreibung',
'config' => array(
'type' => 'text',
)
),
'roles' => array(
'label' => 'Rollen',
'config' => array(
'type' => 'select',
'size' => 10,
'maxitems' => 3,
'foreign_table' => 'tx_people_domain_model_role',
'MM' => 'tx_people_domain_model_person_role_rel',
// 'foreign_table' => 'tx_people_domain_model_person_role_rel',
// 'foreign_field' => 'uid_person',
// 'foreign_label' => 'uid_role',
// 'foreign_selector' => 'uid_role',
// 'foreign_unique' => 'uid_role',
// 'foreign_sortby' => 'sorting',
),
),
'photo' => array(
'exclude' => 0,
'label' => 'Foto',
'config' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getFileFieldTCAConfig('photo', array(
'appearance' => array(
'createNewRelationLinkTitle' => 'Bild hinzufügen',
'collapseAll' => FALSE,
),
'maxitems' => 1,
), $GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'])
),
),
);
?>
更新调试输出:
Domain\People\Domain\Model\Personprototypepersistent entity (uid=1, pid=18)
roles => TYPO3\CMS\Extbase\Persistence\ObjectStorageprototypeobject (3 items)
000000001bb500c600007fe33c9a2f36 => Domain\People\Domain\Model\PersonRelationprototypepersistent entity (uid=1, pid=20)
person => NULL
role => NULL
uid => 1 (integer)
_localizedUid => 1 (integer)modified
_languageUid => NULL
_versionedUid => 1 (integer)modified
pid => 20 (integer)
000000001bb5002400007fe33c9a2f36 => Domain\People\Domain\Model\PersonRelationprototypepersistent entity (uid=2, pid=20)
person => NULL
role => NULL
uid => 2 (integer)
_localizedUid => 2 (integer)modified
_languageUid => NULL
_versionedUid => 2 (integer)modified
pid => 20 (integer)
000000001bb500d100007fe33c9a2f36 => Domain\People\Domain\Model\PersonRelationprototypepersistent entity (uid=3, pid=20)
person => NULL
role => NULL
uid => 3 (integer)
_localizedUid => 3 (integer)modified
_languageUid => NULL
_versionedUid => 3 (integer)modified
pid => 20 (integer)
firstname => 'Max' (3 chars)
lastname => 'Mustermann' (10 chars)
role => 'Rolle' (5 chars)
photo => TYPO3\CMS\Extbase\Domain\Model\FileReferenceprototypepersistent entity (uid=25, pid=18)
description => 'Beschreibungstext' (17 chars)
uid => 1 (integer)
_localizedUid => 1 (integer)modified
_languageUid => NULL
_versionedUid => 1 (integer)modified
pid => 18 (integer)
所以问题是我需要在前端访问那些相关的对象(或者一个人的角色)。
编辑:我想我现在对我需要的关系类型有点困惑。一个人可以有n个角色。无论如何,我不想把人们和角色联系起来。我只想创建角色,然后将角色分配给不同的人。所以我想这应该是1:n的关系。如果这使它变得更容易的话。解决方案是在我的Person类中添加以下方法和变量:
/**
* roles
*
* @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\Domain\People\Domain\Model\Role>
*/
protected $roles = NULL;
/**
* __construct
*/
public function __construct() {
//Do not remove the next line: It would break the functionality
$this->initStorageObjects();
}
/**
* Initializes all ObjectStorage properties
* Do not modify this method!
* It will be rewritten on each save in the extension builder
* You may modify the constructor of this class instead
*
* @return void
*/
protected function initStorageObjects() {
$this->roles = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
}
/**
* Adds a Role
*
* @param \Domain\People\Domain\Model\Role $role
* @return void
*/
public function addRole(\Domain\People\Domain\Model\Role $role) {
$this->roles->attach($role);
}
/**
* Removes a Role
*
* @param \Domain\People\Domain\Model\Role $roleToRemove The Role to be removed
* @return void
*/
public function removeRole(\Domain\People\Domain\Model\Role $roleToRemove) {
$this->roles->detach($roleToRemove);
}
/**
* Returns the roles
*
* @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\Domain\People\Domain\Model\Role> $roles
*/
public function getRoles() {
return $this->roles;
}
/**
* Sets the roles
*
* @param \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\Domain\People\Domain\Model\Role> $roles
* @return void
*/
public function setRoles(\TYPO3\CMS\Extbase\Persistence\ObjectStorage $roles) {
$this->roles = $roles;
}
/**
*角色
*
*@var\TYPO3\CMS\Extbase\Persistence\ObjectStorage
*/
受保护的$roles=NULL;
/**
*_uuu构造
*/
公共函数构造(){
//不要删除下一行:它会破坏功能
$this->initStorageObjects();
}
/**
*初始化所有ObjectStorage属性
*不要修改此方法!
*它将在扩展生成器中的每次保存时重写
*您可以修改此类的构造函数
*
*@返回无效
*/
受保护的函数initStorageObjects(){
$this->roles=new\TYPO3\CMS\Extbase\Persistence\ObjectStorage();
}
/**
*添加一个角色
*
*@param\Domain\People\Domain\Model\Role$Role
*@返回无效
*/
公共函数addRole(\Domain\People\Domain\Model\Role$Role){
$this->roles->attach($role);
}
/**
*删除角色
*
*@param\Domain\People\Domain\Model\Role$Role删除要删除的角色
*@返回无效
*/
公共函数移除OLE(\Domain\People\Domain\Model\Role$roleToRemove){
$this->roles->detach($roleToRemove);
}
/**
*返回角色
*
*@return\TYPO3\CMS\Extbase\Persistence\ObjectStorage$roles
*/
公共函数getRoles(){
返回$this->roles;
}
/**
*设置角色
*
*@param\TYPO3\CMS\Extbase\Persistence\ObjectStorage$roles
*@返回无效
*/
公共函数集合角色(\TYPO3\CMS\Extbase\Persistence\ObjectStorage$roles){
$this->roles=$roles;
}
将类放在这里。90%的用户不会打开链接。你不需要将关系作为一个类,至少对于TYPO3是noc。如果您的应用程序需要它(例如,如果您需要关系上的属性),请创建两个关系:1:n从RolePerson
到Role
和1:n从RolePerson
到Person
。此外,请显示相应的ext\u表。sql
文件和您的模型的TCA配置,如果你已经做了一些的话,还有任何打字稿映射。我认为这可能是缺少setter和/或命名约定的问题。此外,我获得了正确数量的关系对象,但无法访问它的角色/人员对象。。它们显然是空的。我想说明的是,基本上能够访问与该人相关的每个角色。所以我想有一个类person的对象和一个类成员role。
<?php
return array(
'ctrl' => array(
'title' => 'Person',
'label' => 'firstname',
'label_alt' => ',lastname',
'label_alt_force' => TRUE,
'tstamp' => 'tstamp',
'crdate' => 'crdate',
'dividers2tabs' => TRUE,
'delete' => 'deleted',
'enablecolumns' => array(
'disabled' => 'hidden',
),
'iconfile' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extRelPath('people') . 'ext_icon.gif'
),
'types' => array(
'1' => array('showitem' => 'firstname, lastname, role, description, photo, roles')
),
'columns' => array(
'hidden' => array(
'exclude' => 1,
'label' => 'LLL:EXT:lang/locallang_general.xml:LGL.hidden',
'config' => array(
'type' => 'check'
)
),
'firstname' => array(
'exclude' => 0,
'label' => 'Vorname',
'config' => array(
'type' => 'input',
'size' => 225,
)
),
'lastname' => array(
'exclude' => 0,
'label' => 'Nachname',
'config' => array(
'type' => 'input',
'size' => 225,
)
),
'role' => array(
'exclude' => 0,
'label' => 'Rolle',
'config' => array(
'type' => 'input',
'size' => 225,
)
),
'description' => array(
'exclude' => 0,
'label' => 'Beschreibung',
'config' => array(
'type' => 'text',
)
),
'roles' => array(
'label' => 'Rollen',
'config' => array(
'type' => 'select',
'size' => 10,
'maxitems' => 3,
'foreign_table' => 'tx_people_domain_model_role',
'MM' => 'tx_people_domain_model_person_role_rel',
// 'foreign_table' => 'tx_people_domain_model_person_role_rel',
// 'foreign_field' => 'uid_person',
// 'foreign_label' => 'uid_role',
// 'foreign_selector' => 'uid_role',
// 'foreign_unique' => 'uid_role',
// 'foreign_sortby' => 'sorting',
),
),
'photo' => array(
'exclude' => 0,
'label' => 'Foto',
'config' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getFileFieldTCAConfig('photo', array(
'appearance' => array(
'createNewRelationLinkTitle' => 'Bild hinzufügen',
'collapseAll' => FALSE,
),
'maxitems' => 1,
), $GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'])
),
),
);
?>
<?php
return array(
'ctrl' => array(
'title' => 'Relation Table',
'hideTable' => TRUE,
'sortBy' => 'sorting',
// 'tstamp' => 'tstamp',
// 'crdate' => 'crdate',
// 'dividers2tabs' => TRUE,
// 'delete' => 'deleted',
// 'enablecolumns' => array(
// 'disabled' => 'hidden',
// ),
// 'iconfile' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extRelPath('people') . 'ext_icon.gif'
),
'types' => array(
'0' => array('showitem' => 'uid_person, uid_role')
),
'palettes' => array(),
'columns' => array(
// 'hidden' => array(
// 'exclude' => 1,
// 'label' => 'LLL:EXT:lang/locallang_general.xml:LGL.hidden',
// 'config' => array(
// 'type' => 'check'
// )
// ),
'uid_local' => array(
'label' => 'Person',
'config' => array(
'type' => 'select',
'MM' => 'tx_people_domain_model_person_role_rel',
'foreign_table' => 'tx_people_domain_model_person',
'size' => 1,
'minitems' => 0,
'maxitems' => 1,
),
),
'uid_foreign' => array(
'label' => 'Rolle',
'config' => array(
'type' => 'select',
'MM' => 'tx_people_domain_model_person_role_rel',
'foreign_table' => 'tx_people_domain_model_role',
'size' => 1,
'minitems' => 0,
'maxitems' => 1,
),
),
),
);
?>
<?php
return array(
'ctrl' => array(
'title' => 'Rolle',
'label' => 'name',
'tstamp' => 'tstamp',
'crdate' => 'crdate',
'dividers2tabs' => TRUE,
'delete' => 'deleted',
'enablecolumns' => array(
'disabled' => 'hidden',
),
'iconfile' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extRelPath('people') . 'ext_icon.gif'
),
'types' => array(
'1' => array('showitem' => 'name')
),
'columns' => array(
'hidden' => array(
'exclude' => 1,
'label' => 'LLL:EXT:lang/locallang_general.xml:LGL.hidden',
'config' => array(
'type' => 'check'
)
),
'name' => array(
'label' => 'Bezeichnung',
'config' => array(
'type' => 'input',
'size' => 225,
)
),
// 'people' => array(
// 'label' => 'Personen',
// 'config' => array(
// 'type' => 'inline',
// 'foreign_table' => 'tx_people_domain_model_person_role_rel',
// 'foreign_field' => 'uid_role',
// 'foreign_label' => 'uid_person'
// ) ,
// )
),
);
?>
config.tx_extbase {
persistence {
classes {
Domain\People\Domain\Model\PersonRelation {
mapping {
tableName = tx_people_domain_model_person_role_rel
columns {
uid_local.mapOnProperty = person
uid_foreign.mapOnProperty = role
}
}
}
}
}
}
Domain\People\Domain\Model\Personprototypepersistent entity (uid=1, pid=18)
roles => TYPO3\CMS\Extbase\Persistence\ObjectStorageprototypeobject (3 items)
000000001bb500c600007fe33c9a2f36 => Domain\People\Domain\Model\PersonRelationprototypepersistent entity (uid=1, pid=20)
person => NULL
role => NULL
uid => 1 (integer)
_localizedUid => 1 (integer)modified
_languageUid => NULL
_versionedUid => 1 (integer)modified
pid => 20 (integer)
000000001bb5002400007fe33c9a2f36 => Domain\People\Domain\Model\PersonRelationprototypepersistent entity (uid=2, pid=20)
person => NULL
role => NULL
uid => 2 (integer)
_localizedUid => 2 (integer)modified
_languageUid => NULL
_versionedUid => 2 (integer)modified
pid => 20 (integer)
000000001bb500d100007fe33c9a2f36 => Domain\People\Domain\Model\PersonRelationprototypepersistent entity (uid=3, pid=20)
person => NULL
role => NULL
uid => 3 (integer)
_localizedUid => 3 (integer)modified
_languageUid => NULL
_versionedUid => 3 (integer)modified
pid => 20 (integer)
firstname => 'Max' (3 chars)
lastname => 'Mustermann' (10 chars)
role => 'Rolle' (5 chars)
photo => TYPO3\CMS\Extbase\Domain\Model\FileReferenceprototypepersistent entity (uid=25, pid=18)
description => 'Beschreibungstext' (17 chars)
uid => 1 (integer)
_localizedUid => 1 (integer)modified
_languageUid => NULL
_versionedUid => 1 (integer)modified
pid => 18 (integer)
/**
* roles
*
* @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\Domain\People\Domain\Model\Role>
*/
protected $roles = NULL;
/**
* __construct
*/
public function __construct() {
//Do not remove the next line: It would break the functionality
$this->initStorageObjects();
}
/**
* Initializes all ObjectStorage properties
* Do not modify this method!
* It will be rewritten on each save in the extension builder
* You may modify the constructor of this class instead
*
* @return void
*/
protected function initStorageObjects() {
$this->roles = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
}
/**
* Adds a Role
*
* @param \Domain\People\Domain\Model\Role $role
* @return void
*/
public function addRole(\Domain\People\Domain\Model\Role $role) {
$this->roles->attach($role);
}
/**
* Removes a Role
*
* @param \Domain\People\Domain\Model\Role $roleToRemove The Role to be removed
* @return void
*/
public function removeRole(\Domain\People\Domain\Model\Role $roleToRemove) {
$this->roles->detach($roleToRemove);
}
/**
* Returns the roles
*
* @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\Domain\People\Domain\Model\Role> $roles
*/
public function getRoles() {
return $this->roles;
}
/**
* Sets the roles
*
* @param \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\Domain\People\Domain\Model\Role> $roles
* @return void
*/
public function setRoles(\TYPO3\CMS\Extbase\Persistence\ObjectStorage $roles) {
$this->roles = $roles;
}