how to create dynamic form?

i have a form in my yii application. the input field and content of view is dynamic (depend on query result) for example sometimes i have


    <form ...>

    ...

    <input type="checkbox" name="hi" value="yes">

    ...

    </form>

and sometimes


    <form ...>

    <input type="checkbox" name="hi" value="yes">

    <input type="checkbox" name="hi2" value="yes">

    </form>

without framework i query database and depend on result with one loop i cretae form elements. but how to do this in yii? where do put query for creating input element (view or controller)?

if answer is controller how to pass input elements to view with render()?

Its simple

You can use Simple Query method to get the data from the database server and then while rendering use array("data object"=>$data object)