正确的TCA'type'=>'check'的前端映射 [英] Correct frontend mapping of TCA 'type'=>'check'
问题描述
我目前在TYPO3 7/Extbase中实现了一个用户权限对象.按照(简化)将不同的权限映射为INT的位:
I currently implement a user right object in TYPO3 7/Extbase. Different rights are mapped as bits of an INT as per (simplified):
'permissions' => array(
'label' => 'permissions'
'config' => array(
'type' => 'check',
'items' => array(
array('Permission 1', ''),
array('Permission 2', '')
)
)
),
在后端中对此所做的修改可以正常工作,并且这些标志已正确地存储为它们在DB中的相应位.
Modification of this in the Backend works flawlessly and the flags are correctly stored as their corresponding bits in he DB.
如何在前端实现类似的行为?是否有(正确)将位值映射到流体复选框的方法?
How can I achieve similar behaviour in the frontend? Is there a (correct) way of mapping the bit values to fluid checkboxes?
推荐答案
您可以添加用于设置或返回位的自定义setter/getter函数.
You can add custom setter/getter functions that set or return the bits.
在您的模型中:
/**
* @var int
*/
protected $permissions;
添加类似这样的内容:
/**
* @return int
*/
public function getPermission2() {
return $this->permissions & 2 > 0 ? 1 : 0;
}
/**
* @param int $permission2
*/
public function getPermission2($permission2) {
if ($permission2) {
$this->permissions = $this->permissions | 2;
} else {
$this->permissions = $this->permissions ~ 2;
}
}
然后,您可以在f:form.checkbox
或{object.permission2}
中的parameter="permission2"
中找到其他流体视图帮助器.
Then you can parameter="permission2"
in the f:form.checkbox
or {object.permission2}
for other fluid viewhelpers.
PS:对于权限1,您需要将2
更改为1
,对于权限3,它将是4
PS: for permission 1 you need to change the 2
to 1
and for permission 3 it would be 4
这篇关于正确的TCA'type'=>'check'的前端映射的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!