Well, after a lot of research, I managed with some kind of solution, but maybe something is more correct?
Instead of using sfWidgetFormDoctrineChoice, I used sfWidgetFormSelectRadio (but Checkbox can also work, but I don’t know if it can work with other widgets or even select widgets: / just because my business rules require it, SelectRadio was enough in this particular case. ..)
The widget selection option was filled with the results of the previous query, which I used to populate the previous DoctrineChoice widget, which was previously processed, so the identifier of each record was the key and value of each choice:
$imgs = Doctrine_Core::getTable('ProjImages')->getImages();
$choices = array('' => '');
foreach ($imgs as $img):
$choices[$img->getId()] = $img->getId();
endforeach;
Then I also passed the "formatter" widget:
$this->widgetSchema['img'] = new sfWidgetFormSelectRadio(array(
'choices' => $choices,
'formatter' => array($this, 'showAsImages')
));
$this->validatorSchema['img'] = new sfValidatorChoice(array(
'choices' => $choices,
'required' => false
));
"required" = > false , " " , $options ('' = > '').
, :
public function showAsImages($widget, $inputs)
{
$rows = array();
foreach ($inputs as $input)
{
$domdoc = new DOMDocument();
$domdoc->loadHTML($input['label']);
$node = $domdoc->getElementsByTagName('label')->item(0);
if ($node->nodeValue != "")
{
$img = Doctrine_Core::getTable('ProjImages')->find(array($node->nodeValue));
$input['label'] = '<label '.$node->attributes->item(0)->name .
'="'.$node->attributes->item(0)->value.'">' .
'<img src="'.$img->getImg().'" alt="image" />' .
'</label>';
}
$rows[] = $widget->renderContentTag('li',
$input['input'].
$widget->getOption('label_separator').
$input['label']);
}
return $widget->renderContentTag('ul',
implode($widget->getOption('separator'), $rows),
array('class' => $widget->getOption('class')));
}
sfWidgetFormSelectRadio "" ( , , ).
DOMDocument ( ), , "" < lt; img > . , , 'label'...
... , , ... , "", , , , ...
!