mercredi 5 août 2015

Form rendering in Symfony2 -- How do I render a 2D Array as a table of checkboxes?

Maybe my approach to this is not very good (from a data organization standpoint). I am storing a list of permissions for users in the User entity as one field called "permissions" using type=array. The structure of the array will be something like:

  Array (
  'Page 1' => Array (
            0 => 'No access',
            1 => 'Read only',
            2 => 'Edit',
            3 => 'Create and Delete')
  'Page n' => Array (
            0 => 'No access',
            1 => 'Read only',
            2 => 'Edit',
            3 => 'Create and Delete')
       )

The "Pages" come from another Entity called "Page." I want to be able to render this array as a table similar to how Drupal 7 handles its own User Permissions form: http://ift.tt/1JMeo7b

Basically I want to be able to print out a form with table headers "Page, No Access, Read Only, Edit, Create and Delete" and a row structure of "[PAGE NAME], [], [], [], []"

How can this be achieved and have it still be compatible with the Symfony form engine (ie, it reads the array sample I posted above, and it returns that back to the User entity)




Aucun commentaire:

Enregistrer un commentaire