Created
July 16, 2013 13:29
-
-
Save anonymous/6008688 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// in User entity: | |
public function addRole(Role $roles) { | |
$this->roles[] = $roles; | |
return $this; | |
} | |
public function removeRole(Role $roles) { | |
$this->roles->removeElement($roles); | |
} | |
public function getRoles() { | |
return $this->roles->toArray(); | |
} | |
public function addFormRole(Role $roles) { | |
$this->roles[] = $roles; | |
return $this; | |
} | |
public function removeFormRole(Role $roles) { | |
$this->roles->removeElement($roles); | |
} | |
public function getFormRoles() { | |
return $this->roles; | |
} | |
// in UserType: | |
$builder->add('formRoles', 'entity', array( | |
'class' => 'Acme\DemoBundle\Entity\Role', | |
'property' => 'name', | |
'multiple' => 'true', | |
'expanded' => 'true' | |
)); | |
// in template: | |
<div class="control-group"> | |
{{ form_label(form.formRoles, 'Roles', {'label_attr': {'class': 'control-label'}}) }} | |
<div class="controls"> | |
{{ form_errors(form.formRoles) }} | |
{{ form_widget(form.formRoles, {'attr': {'class': 'none'}}) }} | |
</div> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment