Skip to content

Instantly share code, notes, and snippets.

@vojtech-dobes
Created August 27, 2012 08:56
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save vojtech-dobes/3486768 to your computer and use it in GitHub Desktop.
Save vojtech-dobes/3486768 to your computer and use it in GitHub Desktop.
Independent forms in Nette: UI\Form x UI\Control
<?php
use Nette\Application\UI;
class Form extends UI\Control
{
protected function createComponentForm()
{
$form = new UI\Form;
$form->addText('foo');
$form->addSubmit('send');
return $form;
}
public function render()
{
$this->template->setFile(__DIR__ . '/formTemplate.latte');
$this->template->render();
}
}
<?php
use Nette\Application\UI;
use Nette\Latte\Engine;
use Nette\Templating\FileTemplate;
class Form extends UI\Form
{
protected function attached($parent)
{
parent::attached($parent);
if (!$parent instanceof UI\Presenter) return;
$this->addText('foo');
$this->addSubmit('send');
}
public function render()
{
$template = new FileTemplate(__DIR__ . '/formTemplate.latte');
$template->registerFilter(new Engine);
$template->form = $this;
$template->render();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment