Listbox Data

I am very new to YII and the whole MVC architecture so I am looking for as much detail in the answer as possible.

I have a table containing information regarding telephone clients, some of these have a bit field called "istemplate".

On the create form i want a dropdown called "template" where I want to list all the records where the "istemplate" field = 1

I need to understand in which file ie: model view or controller i need to fetch and filter the data, and then how to put it into the dropdown.

Thanks for any help.

Do you want this one?




<?php

$istemplate_model=Modelname::model->findAll(array("condition"=>"istemplate=1"));

$istemplate_data=CHtml::listData($istemplatemodel,'id','name');

?>


<div class="row">

<?php echo $form->labelEx($model,'istemplate'); ?>

<?php echo $form->dropDownList($model,'istemplate',$istemplate_data,array('empty'=>'Select')); ?>

<?php echo $form->error($model,'istemplate'); ?>

</div>



I managed to do it in a single line in the view:


<?php echo $form->dropDownList($model,'template_id',CHTML::listData(ModelName::model()->findAllByAttributes(array('istemplate'=>'1')),'client_id','name')); ?>

Thanks for the help