Undefined variable error in view file

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.

i review your sample code into my own environment and is working fine.

please debug your code using:

[color=#000000]$adtypelist [/color][color=#666600]=[/color][color=#000000] [/color][color=#660066]CHtml[/color][color=#666600]::[/color][color=#000000]listData[/color][color=#666600]([/color][color=#000000]$adtypes[/color][color=#666600],[/color][color=#008800]‘id’[/color][color=#666600],[/color][color=#000000] [/color][color=#008800]‘description’[/color][color=#666600]);[/color][color=#000000] // add this line, and stop the action excution here, to check the array data at first place.[/color][color=#000000][font=arial, verdana, tahoma, sans-serif][size=3]$this->renderText(CJSON::encode([/size][/font][/color][color=#000000][font=arial, verdana, tahoma, sans-serif]$adtypelist[/font][/color][color=#000000][font=arial, verdana, tahoma, sans-serif][size=3]));[/size][/font][/color]