Created
September 15, 2010 15:03
-
-
Save delbono/580852 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
// nella form class | |
class OrdinativiMenuFoodForm extends BaseOrdinativiMenuItemDayForm | |
{ | |
public function configure() | |
{ | |
$this->removeFields(); | |
// choices | |
$menu_item = new OrdinativiMenuItem(); | |
$food_choices = $menu_item->getFoodChoices(); | |
$this->widgetSchema['menu_id'] = new sfWidgetFormInputHidden(); | |
$this->widgetSchema['menu'] = new sfWidgetFormInputHidden(); | |
$this->widgetSchema['week'] = new sfWidgetFormInputHidden(); | |
$this->widgetSchema['day'] = new sfWidgetFormInputHidden(); | |
$this->widgetSchema['food'] = new sfWidgetFormChoice(array( | |
'choices' => $food_choices, | |
'expanded' => false, | |
'multiple' => true, | |
'label'=> ' ' | |
), array('class'=>'multiselect', 'style'=>'width:500px;')); | |
/* provato anche internamente ma non funziona | |
if($this->getOption('food')){ | |
dbg($this->getOption('food')); | |
$this->setDefault( 'food' , $this->getOption('food')); | |
} | |
*/ | |
$this->widgetSchema->setHelp('food', 'Il menù attuale è rappresentato nella colonna di sinistra'); | |
$this->setValidator('food',new sfValidatorChoice(array('choices' => $food_choices )) ); | |
$this->setValidator('menu',new sfValidatorInteger(array('required' => 'The menu field is required')) ); | |
$this->setValidator('week',new sfValidatorInteger(array('required' => 'The week field is required'))); | |
$this->setValidator('day',new sfValidatorInteger(array('required' => 'The day field is required'))); | |
} | |
} | |
// nella action | |
$this->form = new OrdinativiMenuFoodForm(new OrdinativiMenuItemDay(), array('food'=>$food_defaults)); | |
$this->form->setDefaults( array( | |
'food' => $food_defaults, | |
'menu' => $this->getRoute()->getObject()->getId(), | |
'week' => $request->getParameter('week'), | |
'day' => $request->getParameter('day') | |
) | |
); | |
// $food_choices | |
array(6) { | |
[1]=> | |
string(14) "PASTA AL PESTO" | |
[2]=> | |
string(17) "PASTA AL POMODORO" | |
[3]=> | |
string(23) "FRITTATINA AL FORMAGGIO" | |
[4]=> | |
string(14) "LONZA AL FORNO" | |
[5]=> | |
string(7) "Piselli" | |
[6]=> | |
string(19) "Insalatona classica" | |
} | |
// $food_defaults | |
array(4) { | |
[2]=> | |
string(17) "PASTA AL POMODORO" | |
[3]=> | |
string(23) "FRITTATINA AL FORMAGGIO" | |
[4]=> | |
string(14) "LONZA AL FORNO" | |
[5]=> | |
string(7) "Piselli" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment