form creation createComponent and render methods
- thcom
- Backer | 94
hi i have function which creates a from
<?php
public function createComponentFakturaPolozkyEditForm($name) {
?>
and i have a render function
<?php
public function renderFakturaPolozkyEdit($id) {
$this->template->form = $this['fakturaPolozkyEditForm'];
?>
i am confused, because sometimes i NEED use the
<?php
$this->template->form = $this['fakturaPolozkyEditForm'];
?>
statement, and sometimes NOT
i believe, that form creates when i use {form fakturaPolozkyEditForm} in template
thank for explanation
Last edited by thcom (2013-06-05 15:39)
- hAssassin
- Member | 293
Both ways are possible, but the second one is ugly. I think, that
createComponentFakturaPolozkyEditForm
method should be
like this:
public function createComponentFakturaPolozkyEditForm() {
$form = new UI\Form;
...
return $form;
}
and then you could create this component lazy in template by
{control fakturaPolozkyEditForm}
macro.
EDIT: hence no $name
or $parent
is not mandatory to
pass in createComponent
method.
Last edited by hAssassin (2013-06-05 17:05)
- Vojtěch Dobeš
- Gold Partner | 1316
The form is created when the
createComponentFakturaPolozkyEditForm
method is called. That method
is called internally, and that is in all these cases:
$this->getComponent('fakturaPolozkyEditForm')
$this['fakturaPolozkyEditForm']
{control fakturaPolozkyEditForm}
{form fakturaPolozkyEditForm}
Of course the method will be called just once, next time in any of these cases, the same instance will be returned.
You should never need to pass the form directly into template, because both
{control
and {form
macros are able to access the
component by its name.