Vlastní container-componenta ve formuláři
- Chuchy
- Člen | 77
Ahoj,
snažím se udělat FormContainer jako Component a nějak se mi to nedaří mohl by někdo říct, kde mám chybu? Nebo mi říct, jaký je best practice, pro znovu použití části formuláře?
FormBuilder
$form = $this->formFactory->create();
$form->addComponent(
$this->userHierarchyTreeComponentFactory->create(),
"user_hierarchy_tree"
);
return $form;
UserHierarchyTreeContainerFactory
public function create(): UserHierarchyTreeContainer
{
return new UserHierarchyTreeContainer($this->userHierarchyTreeService);
}
UserHierarchyTreeContainer
class UserHierarchyTreeContainer extends Container
{
/**
* UserHierarchyTreeContainer constructor.
* @param UserHierarchyTreeService $userHierarchyTreeService
* @throws Exception
* @throws \Throwable
*/
public function __construct(
UserHierarchyTreeService $userHierarchyTreeService
)
{
parent::__construct();
foreach ($userHierarchyTreeService->getUserUserHierarchyTreeArray() as $login => $fullName) {
$this->addCheckbox($login, $fullName);
}
}
public function render()
{
$userHierarchyTreeRender = new UserHierarchyTreeRender($this);
$userHierarchyTreeRender->render();
}
}
UserHierarchyTreeRender
class UserHierarchyTreeRender extends Control
{
/** @var UserHierarchyTreeContainer */
private $userHierarchyTreeContainer;
/**
* UserHierarchyTreeRender constructor.
* @param UserHierarchyTreeContainer $userHierarchyTreeContainer
*/
public function __construct(
UserHierarchyTreeContainer $userHierarchyTreeContainer
)
{
parent::__construct();
$this->userHierarchyTreeContainer = $userHierarchyTreeContainer;
}
public function render()
{
$template = $this->template;
$template->setFile(__DIR__ . '/templates/default.latte');
$template->render();
}
}
Component '' is not attached to ‚Nette\Application\UI\Presenter‘. Chyba v render UserHierarchyTreeRender
Editoval Chuchy (31. 10. 2018 14:25)