form creation createComponent and render methods

thcom
Member | 95
+
0
-

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 (5. 6. 2013 15:39)

Felix
Moderator | 1279
+
0
-

You can use default behavior in template – {control formName}.

Or you can use other option

public function actionEdit() {
	$this->template->form = $this['fakturaPolozkyEditForm'];
}

{control $form}

hAssassin
Member | 293
+
0
-

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 (5. 6. 2013 17:05)

Vojtěch Dobeš
Nette Partner | 1316
+
0
-

The form is created when the createComponentFakturaPolozkyEditForm method is called. That method is called internally, and that is in all these cases:

  1. $this->getComponent('fakturaPolozkyEditForm')
  2. $this['fakturaPolozkyEditForm']
  3. {control fakturaPolozkyEditForm}
  4. {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.

RSS feed Topic closed