code_junkie

Zend Framework - Zend_Form Decorator Issue

Nov 13th, 2011
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 KB | None | 0 0
  1. class Core_Form extends Zend_Form
  2. {
  3. protected static $_elementDecorators = array(
  4. 'ViewHelper',
  5. 'Errors',
  6. array('Label'),
  7. array('HtmlTag', array('tag' => 'li')),
  8. );
  9.  
  10. public function loadDefaultDecorators()
  11. {
  12. $this->setElementDecorators(self::$_elementDecorators);
  13. }
  14. }
  15.  
  16. class ExampleForm extends Core_Form
  17. {
  18. public function init()
  19. {
  20. // Example Field
  21. $example = new Zend_Form_Element_Hidden('example');
  22. $this->addElement($example);
  23. }
  24. }
  25.  
  26. <?php echo $this->exampleForm->example; ?>
  27.  
  28. <li><input type="hidden" name="example" value=""></li>
  29.  
  30. class ExampleForm extends Core_Form
  31. {
  32. public function init()
  33. {
  34. //Example Field
  35. $example = new Zend_Form_Element_Hidden('example');
  36. $this->addElement($example);
  37. }
  38.  
  39. public function loadDefaultDecorators()
  40. {
  41. $this->example->setDecorators(array('ViewHelper'));
  42. }
  43. }
  44.  
  45. <?php echo $this->exampleForm->example->setDecorators(array('ViewHelper')) ; ?>
  46.  
  47. class M_Form_Element_Hidden extends Zend_Form_Element_Hidden {
  48. public function init() {
  49. $this->setDisableLoadDefaultDecorators(true);
  50. $this->addDecorator('ViewHelper');
  51. $this->removeDecorator('DtDdWrapper');
  52. $this->removeDecorator('HtmlTag');
  53. $this->removeDecorator('Label');
  54. return parent::init();
  55. }
  56. }
  57.  
  58. $element = new M_Form_Element_Hidden('myElement');
  59. $this->addElement($element);
  60.  
  61. $this->addElement(
  62. 'text',
  63. 'a1',
  64. array('required' => true, 'validators' => array('Alpha'))
  65. );
  66.  
  67. $this->setElementDecorators(array('ViewHelper'));
  68.  
  69. $nombre1 = new Zend_Form_Element_Text(
  70. 'n1',
  71. array('id'=> 'Nombre1', 'validators' => array('Alpha') )
  72. );
  73. //$nombre1->setDecorators(array('ViewHelper'));
  74. $this->addElement($nombre1);
  75.  
  76. //$nombre1->setDecorators(array('ViewHelper'));
Add Comment
Please, Sign In to add comment