问题
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', '')
)
)
),
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?
回答1:
You can add custom setter/getter functions that set or return the bits.
in your model:
/**
* @var int
*/
protected $permissions;
Add something like this:
/**
* @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;
}
}
Then you can parameter="permission2"
in the f:form.checkbox
or {object.permission2}
for other fluid viewhelpers.
PS: for permission 1 you need to change the 2
to 1
and for permission 3 it would be 4
来源:https://stackoverflow.com/questions/41569091/correct-frontend-mapping-of-tca-type-check