I currently have a zend framework application with multiple modules. Each module should be using the same Zend_Form_Decorator_ViewScript, located in the default
modules /views/scripts
folder.
Without any changes, modules by default only look for form decorator viewscripts in their own /views/scripts
folder located under each module, so to get them to load them from default
modules folder, I first need to apply this within the form:
$view = new Zend_View();
$view->setScriptPath(APPLICATION_PATH . '/views/scripts');
$this->setView($view);
Within that same form, I create multiple Zend_Form_SubForm
s, for which I need to apply that same code again. If that isn't enough, I need to apply that path to each individual element in each SubForm as well as the parent form. Additionally, each element has to have its ViewScript defined each time like:
$username->setDecorators(array(array('ViewScript', array('viewScript' => '/formScripts/wizardElement.phtml'))));
Now, it all works if I define all of that for each element/subform/form within the same file, but it just seems so much unnecessary work/code.
- Can the process be simplified firstly
by just having the parent form define
the
scriptPath
for itself, its elements, its subforms, and the subforms elements? - Can new elements created automatically have specific
ViewScripts
defined for them, based on what type of element it is (i.e. input box, checkbox, selectbox, textarea, button etc)?
I am currently extending my form directly from the default Zend_Form
, I won't have a problem of creating an own abstract form to extend my forms from, but especially with the scriptPath
problems, I am not entirely sure how I should approach this whole problem.
Applying:
$this->setSubFormDecorators(array(
'Form',
array('ViewScript', array('viewScript' => '/formScripts/wizardSubForm.phtml'))
));
overwrites all the element specific decorators I've applied before it.
Suggestions?