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

Split up EmbedRelations in form by IDs Symfony

  • REFUNDED

Hello,

<strong>Note: This has been solved with the help from dustin10 on #symfony. Please see my discourse below for more information.</strong>

I'm editing a product and its current properties in a form with embedRelation('ProductProperty'). Everything is good so far. E/R diagram here [[LINK href="http://d.pr/1N7R"]]http://d.pr/1N7R[[/LINK]]

However, now I want to split up the form and show attribute sets in different AJAX tabs according to its SetID. I still want to have a single 'Save' button, but it is not critical if I need to have multiple. How can I do this?

In my _form.php I'm iterating Sets but I can't seem to get the SetID for the ProductProperty form object. Am I going about this the wrong way?

I'm using symfony 1.4 and Doctrine 1.2.

class ProductForm extends BaseProductForm
{
public function configure()
{
unset($this['created_at'], $this['updated_at'], $this['properties_list'], $this['id'], $this['slug']);

$this->embedRelation('ProductProperties');
}
}


_form.php:

<?php foreach($sets as $set) : ?>
<div id="tabs-<?php echo $set->getId() ?>">
<h3><?php echo $set->getTitle() ?></h3>

<table class="form">
<tfoot></tfoot>
<tbody>
<?php if($set->getId() == 1) : ?>
<tr>
<th><?php echo $form['title']->renderLabel() ?></th>
<td><?php echo $form['title'] ?></td>
<td><?php echo $form['title']->renderError() ?></td>
</tr>
<tr>
<th><?php echo $form['sku']->renderLabel('SKU') ?></th>
<td><?php echo $form['sku'] ?></td>
<td><?php echo $form['sku']->renderError() ?></td>
</tr>
<tr>
<th><?php echo $form['category_id']->renderLabel() ?></th>
<td><?php echo $form['category_id'] ?></td>
<td><?php echo $form['category_id']->renderError() ?></td>
</tr>

<?php foreach($form['ProductProperties'] as $eForm) : ?>
<tr>
<th><?php echo $eForm->renderLabel() ?></th>
<td><?php echo $eForm['value'] ?></td>
<td><?php echo $eForm->renderError() ?></td>
</tr>
<?php endforeach; ?>

<?php endif; ?>
</tbody>
</table>
</div>
<?php endforeach; ?>


Here is my schema.yml:

Product:
tableName: products
actAs:
Timestampable: ~
Sluggable:
unique: true
fields: [title]
canUpdate: true
columns:
id:
type: integer
primary: true
autoincrement: true
category_id:
type: integer
notnull: true
sku:
type: string(50)
notnull: true
title:
type: string(150)
notnull: true
relations:
Category:
foreignType: many
foreignAlias: Products

Property:
tableName: properties
actAs:
Timestampable: ~
Sluggable:
unique: true
fields: [description]
canUpdate: true
columns:
id:
type: integer
primary: true
autoincrement: true
set_id:
type: integer
notnull: true
description:
type: string(100)
notnull: true
relations:
Set:
foreignType: many
foreignAlias: Properties

Set:
tableName: sets
actAs:
Timestampable: ~
columns:
id:
type: integer
primary: true
autoincrement: true
title:
type: string(100)
notnull: true

ProductProperty:
tableName: product_properties
actAs:
Timestampable: ~
columns:
product_id:
type: integer
primary: true
property_id:
type: integer
primary: true
value:
type: text
notnull: true
relations:
Product:
alias: Product
foreignType: many
foreignAlias: ProductProperties
onDelete: cascade
Property:
alias: Property
foreignType: many
foreignAlias: PropertyProperties
onDelete: cascade

Answers (1)

2011-04-07

anil gupta answers:

you can do like this

<?php $eForm = $form['ProductProperties'] ?>
//initialize $eform at the top //

now u can render field in any place of the document by using
<?php echo $eForm['fieldname']->rander() ?>