質問

Like described in the title, i' trying to use a dropdownlist for post back page. The post is receive in the controller but the value selected is empty. Here is my dropdownlist

<?php echo CHtml::dropDownList('groupe',$groupe, 
array("A"=>"A","B"=>"B","C"=>"C","D"=>"D","E"=>"E","F"=>"F","G"=>"G","H"=>"H"),
array(
'prompt'=>'--Choisir un groupe--',
'submit'=>CController::createUrl('classement'),
//'data'=>array('groupe'=>'js:this.value'),
));  ?>

And here is my controller

public function actionClassement($groupe="")
    {echo $groupe;
            if(isset($_POST['groupe'])){echo $_POST['groupe']."ici=".$groupe;
                $groupe = $_POST['groupe'];
            }echo 'test';
            $model = Team::model()->getClassementByGroupe($groupe);
            $games = array();
            $games = Game::model()->getGameByGroupe($groupe);
            //echo '<pre>test';echo print_r($model);echo '</pre>';
            $this->render('classement',array(
                    'model'=>$model,
                    'groupe'=>$groupe,
                    'games'=>$games,
            ));
    }

Thanks for your help because i don't find my mistake :-s

役に立ちましたか?

解決

You need to wrap your dropdown in a form. This worked. Also note $groupe gets assigned if there is a $_GET variable. Your combo is posting, so you need to use $_POST['groupe']

<form method="post" action="<?= $this->createUrl('') ?>">
  <?php
  echo CHtml::dropDownList('groupe', $groupe, array(
      "A" => "A",
      "B" => "B",
      "C" => "C",
      "D" => "D",
      "E" => "E",
      "F" => "F",
      "G" => "G",
      "H" => "H"
          ), array(
      'prompt' => '--Choisir un groupe--',
      'submit' => CController::createUrl('classement'),
          //'data'=>array('groupe'=>'js:this.value'),
  ));
  ?>


</form>

I removed the models for testing the controller.

public function actionClassement($groupe = "") {
  echo $groupe;
  if (isset($_POST['groupe'])) {
    echo $_POST['groupe'] . "ici=" . $groupe;
    $groupe = $_POST['groupe'];
  }echo 'test';
//   $model = Team::model()->getClassementByGroupe($groupe);
//   $games = array();
//   $games = Game::model()->getGameByGroupe($groupe);
  //echo '<pre>test';echo print_r($model);echo '</pre>';
  $this->render('view', array(
      'groupe' => $_POST['groupe'],
  ));
}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top