Ask your Symfony questions! Pay money and get answers fast! (more info)

Form getObject equivalent in an Embedded Relation Symfony

  • SOLVED

Hello,

I am a bit stuck on an issue in a form with an Embedded Relation.

I am creating a scheduling application. There is an event and associated with that, is a list of people who are available to staff it. I want to be able to edit these as a 1 to many relation.

Here is a screen snap of the form:

[[LINK href="http://public.cogorno.com/Scheduling.png"]][[/LINK]]


The relation has three columns:

Staff Person Name Role Availability


Everything works fine, but I would like to make the first column (staff person's name) read-only. I don't want the scheduler to be able to change the person.

In a NON-embedded form, I would remove the field from the form and use the getObject() function to access the data directly. Example:

<?php echo $form->getObject()->getFullName() ?>


Here is the HTML for the embedded relation in my _form.php partial:


<table>
<tbody>
<?php foreach ($form['Schedule'] as $scheduleRow) : ?>
<tr>
<td> <?php echo $scheduleRow->getObject()->getFullName() ?> </td>n
<td> <?php echo $scheduleRow['role_id'] ?> </td>
<td> <?php echo $scheduleRow['status_id'] ?> </td>
<?php endforeach ; ?>
</tbody>
</table>




However, the getObject() function doesn't exist for the embedded form variable ($scheduleRow). How can I get access to the object associated with the row?

Or, if there is another way to make the name read-only, that would work too.


Thanks for any suggestions you have!

-Steve

Answers (1)

2011-09-12

Benjamin Lévêque answers:

You can use this

<?php $object = $form->getObject() ?>
<table>
<tbody>
<?php foreach ($form['Schedule'] as $i => $scheduleRow) : ?>
<tr>
<td><?php echo $object->Schedule[$i]->getFullName() ?></td>
<td><?php echo $scheduleRow['role_id'] ?> </td>
<td><?php echo $scheduleRow['status_id'] ?> </td>
<?php endforeach ; ?>
</tbody>
</table>


and you also need to remove the fullname widget from the embeded form


Steven Cogorno comments:

This is exactly what I needed. THANK YOU!