What i want to do is, to get the selected Id from the dropDownList into my criteria of another model.
the dropDownList
<?php echo $form->dropDownList($model,'bereichId', CHtml::listData(Bereich::model()->findAll(), 'id', 'name'),
array(
'ajax' => array(
'type'=>'POST', //request type
'url'=>$this->createUrl('Fragen/dynamicFragen'),
))); ?>
I don’t know, what to write into the action dynamicFragen. Or even write a javascript funktion.
the Controller Bereichfragen
public function actionCreate()
{
$model=new Bereichfragen('search');
$model2=new Fragen('search');
$model2->unsetAttributes();
if(isset($_GET['Fragen']))
$model2->attributes=$_GET['Fragen'];
if(isset($_POST['Bereichfragen']))
{
foreach ($_POST['selectedIds'] as $id)
{
$model=new Bereichfragen();
$model->aktiv=$_POST['Bereichfragen']['aktiv'];
$model->bereichId=$_POST['Bereichfragen']['bereichId'];
$model->fragenId=$id;
$model->save();
}
}
$this->render('create',array(
'model'=>$model,
'model2'=>$model2,
));
}
the Model Fragen
public function searchFragen()
{
// Warning: Please modify the following code to remove attributes that
// should not be searched.
$criteria=new CDbCriteria;
$criteria->with = array('kategorie');
$criteria->alias = 'fragen';
$criteria->addCondition('not exists(
SELECT * FROM bereich b, bereichfragen bf
where b.id = bf.bereichId and
bf.fragenId = fragen.id and
b.id = 2)'); //put selection here
$criteria->compare('id',$this->id,true);
$criteria->compare('text',$this->text,true);
$criteria->compare('kategorieId',$this->kategorieId);
$criteria->compare('kategorie.name', $this->kategorie_search, true );
Now i want instead of the 2 the selected Id from my dropDownList.
Please help me.