Advertisement
Guest User

Untitled

a guest
Feb 9th, 2015
284
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. class UnitFieldset extends Fieldset implements ServiceLocatorAwareInterface
  2. {
  3. protected $serviceLocator;
  4.  
  5. public function init()
  6. {
  7. $unitTable = $this->getFormFactory()
  8. ->getFormElementManager()
  9. ->getServiceLocator()
  10. ->get('Unit\Model\UnitTable')
  11. ->fetchAll() ;
  12. ;
  13.  
  14. $this->setObject(new Unit())
  15. ->setHydrator(new ClassMethods());
  16.  
  17.  
  18.  
  19.  
  20. $selectData = array();
  21.  
  22. foreach ( $unitTable as $selectOption ) {
  23. $selectData[ $selectOption->UnitID ] = $selectOption->UnitFullName;
  24. }
  25.  
  26. $this->add([
  27. 'name' => 'srcUnit',
  28. 'type' => 'Select',
  29. 'options' => array(
  30. 'label' => ' Unit ',
  31. 'label_attributes' => array(
  32. 'class' => 'control-label text-left'
  33. ),
  34. 'value_options' => $selectData,
  35. ),
  36. 'attributes' => array(
  37. 'class' => 'form-control input-sm chosen-select-deselect chosen-select-width'
  38. )
  39. ]) ;
  40.  
  41. return $this;
  42.  
  43. }
  44.  
  45. public function setServiceLocator(ServiceLocatorInterface $sl)
  46. {
  47. $this->serviceLocator = $sl;
  48. }
  49.  
  50. public function getServiceLocator()
  51. {
  52. return $this->serviceLocator;
  53. }
  54. }
  55.  
  56.  
  57. ////MainForm
  58. $this->add(array(
  59. 'type' => 'Collection',
  60. 'name' => 'srcUnits',
  61. 'options' => array(
  62. 'label' => '',
  63. 'count' => 1,
  64. 'should_create_template' => true,
  65. 'allow_add' => true,
  66. 'use_as_base_fieldset' => false,
  67. 'create_new_objects' => true,
  68. 'target_element' => array('type' => 'UnitFieldset')
  69. ),
  70. ));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement