form handle method registration

Notice: This thread is very old.
kapcus
Member | 3
+
0
-

Hi,

with respect of future Nette and PHP development, what is the preferred way how to register handle method on form ?

<?php
$this->addSubmit('b_save', 'Save')->onSuccess[] = array($this, 'testFormSucceeded')
?>

or

<?php
$this->addSubmit('b_save', 'Save')->onSuccess[] = $this->testFormSucceeded
?>

Thx

Pavel Kravčík
Member | 1195
+
+3
-

I prefer this one:

[$this, 'testFormSucceeded']
Henix
Member | 1
+
0
-

Im using callable method

$this->testFormSucceeded
CZechBoY
Member | 3608
+
+2
-

Or via anonymous function, which calls private handle method.

public function create ()
{
	$form->onSuccess[] = function (Form $form, ArrayHash $values) {
		$this->processForm($form, $values);
	};
}

private function processForm (Form $form, ArrayHash $values)
{
	// process
}
Pavel Kravčík
Member | 1195
+
0
-

@CZechBoY: This shouldn't be preferred way. :)

David Matějka
Moderator | 6445
+
0
-

@CZechBoY I also use this very often. Great advantage is that static analysis (references, refactoring…) works well