Skip to content

Instantly share code, notes, and snippets.

@enumag
Created February 4, 2013 22:03
Show Gist options
  • Select an option

  • Save enumag/4710107 to your computer and use it in GitHub Desktop.

Select an option

Save enumag/4710107 to your computer and use it in GitHub Desktop.
FormFactory
<?php
namespace App;
class UserFormFactory extends \Nette\Object
{
/**@var \Model\UserRepository */
private $userRepository;
/**
* @param \Model\UserRepository $userRepository
*/
public function __construct(\Model\UserRepository $userStatusRepository)
{
$this->userRepository = $userRepository;
}
/**
* @return \Nette\Application\UI\Form
*/
public function create()
{
$form = new \Nette\Application\UI\Form
// díky tomu že je to factory (služba) mohu injectnout nějaké modely a podle nich testovat i unikátnost etc.
$form->onSuccess[] = callback($this, 'save');
return $form;
}
public function save(\Nette\Application\UI\Form $form)
{
// uložení do injectnutých modelů
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment