Say you have a search form on a page that lists customers but you also want the same form on the main dashboard page. You have two options: either define your form in a third place and use that definition in both createComponent… methods, or you can create it with createComponent… in BasePresenter and inherit it by both the CustomerPresenter and the DashboardPresenter. Or you can use a hack.
To be honest, there’s no real reason why you would want to use a hack when you have two comfortable and legitimate options. For me it was just a mind twisting practice. I wanted to find a way to define the form in CustomerPresenter and somehow use that definition in DashboardPresenter.
Here’s the form owner code. Typically a presenter that handles administration of certain entity.
-
span class=”st0″>’name’, ‘Company or Contact Name’‘search’, ‘Search’‘customersFilterSubmitted’// do your magic
-
}
-
}
And here’s a factory method in the other presenter that also needs to use the form.
-
span class=”st0″>’customersFilterForm’‘name’]->caption = ‘Name’; // you can manipulate the form elements the same way you’re used to
-
‘Customer:default’‘do’‘submit’
Tags: Nette Framework 2.0-beta (revision f38d86f released on 2011-08-24)