Skip to content

Instantly share code, notes, and snippets.

@jsmitka
Created March 30, 2010 17:02
Show Gist options
  • Save jsmitka/349303 to your computer and use it in GitHub Desktop.
Save jsmitka/349303 to your computer and use it in GitHub Desktop.
{block #content}
{? $form = $component['form']}
{widget form 'begin'}
{widget form 'errors'}
<table>
<thead>
<tr>
<th>&nbsp;</th>
<th>Jméno</th>
<th>URL</th>
<th>Popis</th>
</tr>
</thead>
<tbody>
{foreach $items as $item}
<tr>
<td>{$form['items'][(string) $item->id]->getControl()}</td>
<td>{$item->name}</td>
<td>{$item->url}</td>
<td>{$item->description}</td>
</tr>
{/foreach}
</tbody>
</table>
{widget form 'body'}
{widget form 'end'}
<?php
class TestPresenter extends BasePresenter
{
/**
* @var DibiResult
*/
protected $items;
public function actionDefault()
{
$this->items = $model->getServicestate();
}
public function renderDefault()
{
$this->template->items = $this->items;
}
public function createComponentForm()
{
$form = new AppForm();
$items = $form->addContainer('items');
foreach ($this->items as $item) {
$items->addCheckbox((string) $item->id, '');
}
$form->addSubmit('approve', 'Schválit');
$form->addSubmit('delete', 'Smazat');
$form->onSubmit[] = array($this, 'form_Submit');
return $form;
}
public function form_Submit(Form $form)
{
$values = $form->getValues();
$items = array();
foreach ($values['items'] as $id => $value)
if ($value) $items[] = $id;
// pole $items obsahuje seznam IDček
if ($form['approve']->isSubmittedBy()) {
// ...
} elseif ($form['delete']->isSubmittedBy()) {
// ...
}
$this->redirect('this');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment