Created
December 21, 2012 20:15
-
-
Save bakura10/4355470 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Foo | |
{ | |
protected $labelCallable; | |
public function setLabelCallable($labelCallable) | |
{ | |
$this->labelCallable = $labelCallable; | |
} | |
... | |
public function doSomething() | |
{ | |
// find your object... | |
$object = ...; | |
if (is_callable($this->labelCallable)) { | |
$label = $this->labelCallable($object); | |
} | |
} | |
} | |
// So in your form you can do something like this : | |
$this->add(array( | |
'name' => 'someName', | |
'type' => 'MyNamespace\Form\Element\EntitySelect', | |
'attributes' => array( | |
'required' => true | |
), | |
'options' => array( | |
'label' => 'Select element Label', | |
'empty_option' => '--- Choose Entity ---', | |
'object_manager' => $this->getEntityManager(), | |
'target_class' => 'MyNamespace\Entity\TargetEntity', | |
'label_callable' => function($object) { | |
return $object->propertyOne + ' - ' + $objectPropertyTwo; | |
} | |
) | |
)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment