Zend 1 to Zend 2, was using decorators, how can i achieve the same behavior now? -


the title of question not self-explanatory, there tons of questions migrating zend 1 app zend 2 one, i'll cut specifics of problem.

first , foremost used decorators our form elements inside our view files, this:

$element = new zend_form_element_text('element'); $element->setlabel('element'); $element->setrequired(); $element->setdecorators(array(new nti_form_decorator_item()) ); print $element; 

the new nti_form_decorator_item() part decorator in question. class receives element , added custom html render inside view. instead of simple label/input, nice divs custom classes wraping whole thing.

class nti_form_decorator_item extends zend_form_decorator_abstract { ... ... public function render($content) {     $element = $this->getelement();     // build html here, using methods of      // zend_form_decorator_abstract class.     return html_entity_decode($html); } 

this way did in zend 1, old nice decorators.
team decided update framework, having lots of trouble our views, apparently decorator thing long gone , didn't find quick , easy way achieve same results in terms of customization of view files (every single 1 of form elements inside our views used decorator standard design).

i have looked upon things viewhelper , stuff, couldn't understand how it.

can provide me advice on how can it?

if want same markup around every element, simplest way override formrow() helper. define own version of helper:

namespace nti\form\view\helper;  use zend\form\view\helper\formrow zfformrow; use zend\form\elementinterface;  class formrow extends zfformrow {     /**      * @param  elementinterface $element      * @throws \zend\form\exception\domainexception      * @return string      */     public function render(elementinterface $element)     {         // build markup here         $html = '<div>';         $html .= parent::render($element);         $html .= '</div>';          return $html;     } } 

and add invokable module.config.php:

'view_helpers' => array(     'invokables' => array(         'form-row' => 'ntiform\form\view\helper\formrow'     ) ) 

Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

Kivy: Swiping (Carousel & ScreenManager) -