DropDownList yet again [SOLVED]

Hello

I am trying to create a dropdownlist in my view that basically pulls in the options from another model can you have a look to see what im doing wrong. the list is created but when i select and save i get no data inputed into the database and i get the error message field cannot be empty (it should do this if it’s empty).

Heres the code from my view.

[color="#2E8B57"]




               <div class="row">

		<?php 

                echo $form->labelEx($model,'Broker_Id');

		$models = BrokerDetails::model()->findAll(array('order' => 'Company_Name')); //This works fine pulling in the data from my BrokerDetails model

		$list = CHtml::listData($models, 'Broker_Id', 'Company_Name');              // This Also Works Fine when i display $list using print_r i can see the full array

		echo CHtml::dropDownList('Broker_Id',$brokers,$list);                      // This works to the point that it displays the correct drop down list but when i select an option and save it inputs nothing into the broker_id field of my client table in my database.

 		echo $form->error($model,'Broker_Id'); 

                ?>

		</div><!-- row -->



[/color]

Bear in mind that i’m a total noob and i haven’t made any other changes elsewhere this is the only place i have created the code do i need to change my model or controller?

Anyways i hope you can help i have read all the tutorials and i have both of the books and i can’t do this simple thing.

Ibecake…




echo $form->dropDownList($model, 'Broker_id', $list);



Brilliant works grand now thanks excellent stuff.

Ibecake…

Just to put up the total solution for some one else.

So if you want to pull data from another model and present it in a dropdownlist in your view this is what you do.


                <div class="row">

                <?php 

                echo $form->labelEx($model,'Broker_Id');

                $models = BrokerDetails::model()->findAll(array('order' => 'Company_Name')); //This works fine pulling in the data from my BrokerDetails model

                $list = CHtml::listData($models, 'Broker_Id', 'Company_Name');              // This takes the data from $models and creates $list for the dropDownList in my case Broker_id is the value of each option(Company_Name) in the list. So the user selects the company name from the list and the broker_id is entered into the client_details table under the broker_id field. 

                echo $form->dropDownList($model, 'Broker_Id', $list);                     // This generates the DropDownList using the array $list and enters the selection into the Broker_Id field of my client_details table as this is the form for my Client_details Table.

                echo $form->error($model,'Broker_Id'); 

                ?>

                </div><!-- row -->

Anyways i hope it helps someone else and a big thank you to softark who gave me the solution in the first place.

Ibecake