Вот пример с этой простой схемой. Вы должны быть в состоянии приспособить его к вашим потребностям.
//schema.yml
Client:
columns:
name: string(255)
service_id: integer
relations:
Service:
local: service_id
foreign: id
foreignAlias: Clients
Service:
columns:
name: string(255)
//routing.yml
//i added this route to split 'new' action in 2 steps
service_choose:
url: /service/choose
param: {module: service, action: choose}
service:
class: sfDoctrineRouteCollection
options:
model: Service
module: service
//create a module based on service route collection (there's a task) and add choose action:
public function executeChoose(sfWebRequest $request)
{
$form = new ServiceChooseForm();
if (($method = $this->request->getMethod()) == 'POST')
{
$form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
if ($form->isValid())
{
$total_clients = $form->getValue('total_clients');
$this->redirect('@service_new?total_clients='.$total_clients);
}
}
$this->form = $form;
$this->setTemplate('choose');
}
Вам также необходимо создать собственную форму sfForm для действия выбора, в которой вы устанавливаете количество клиентов.
class ServiceChooseForm extends sfForm
{
public function configure()
{
$this->widgetSchema->setNameFormat('service[%s]');
$this->setWidget('total_clients', new sfWidgetFormInput());
$this->setValidator('total_clients', new sfValidatorInteger());
}
}
//ServiceForm embeds your new clients forms based on total_clients option.
class ServiceForm extends BaseServiceForm
{
public function configure()
{
//clients sub form
$clientsForm = new sfForm();
for ($i=0; $i<$this->getOption('total_clients',2); $i++)
{
$client = new Client();
$client->Service = $this->getObject();
$clientForm = new ClientForm($client);
$clientsForm->embedForm($i, $clientForm);
}
$this->embedForm('newClients', $clientsForm);
}
}
Еще несколько настроек:
//chooseSuccess template, poinst a form to the same action:
<h1>New Service</h1>
<form action="<?php echo url_for('service_choose') ?>" method="post">
<table>
<tfoot>
<tr>
<td colspan="2">
<?php echo $form->renderHiddenFields(false) ?>
<input type="submit" value="Continue" />
</td>
</tr>
</tfoot>
<tbody>
<?php echo $form ?>
</tbody>
</table>
</form>
//_form partial:
<form action="<?php echo url_for('@service_create?total_clients='. $form->getOption('total_clients')) ?>" method="post">
Вот и все. Надеюсь, вы можете собрать все это вместе =)