I am trying to setup list data for a dropdown in my view file. I created the following function in the controller:
public function actionCreate()
{
//define the model
$model=new AdRates;
//get the drop down data from the ad type model
$adtypes = AdTypes::model()->findAll();
$adtypelist = CHtml::listData($adtypes,'id', 'description');
if(isset($_POST['AdRates']))
{
$model->attributes=$_POST['AdRates'];
if($model->save())
$this->redirect(array('view','id'=>$model->id));
}
//send the data to the form
$this->render('create',array('model'=>$model,'adtypelist'=>$adtypelist));
}
In the view file, I have the following code to implement a drop down:
<?php echo $form->dropDownList($model,'adtype_id', $adtypelist,array('empty'=>'Please Select')); ?>
I keep getting an error saying that $adtypelist is not defined. Any help would be appreciated.
Also, I want to add that I have defined the relationships between the 2 tables in the corresponding model files, i.e belongs to, has many.