Active Record

Hi Guys

I am new to this framework and I am just finding my way through it.

It looks promising, and I think I am going to use it for an upcoming project.  I just have a question.

I know this is probably a simple question, but how can I get a list of all the categories (i have a categories model)  from the products controller(also have a product model) and then add it to the view and make it accessible via a drop down?

Thanks for your help in advanced.

Category::model()->findAll(). You don't need to get the list via Product model since they are not related yet.

I have the following code in the view :

<?php  echo CHtml::activeDropDownList($products,'categoryID', Categories::model()->findAll() ); ?>

I get the following error when I run that code:

Object of class categories could not be converted to string

Any ideas what I am doing wrong?


Figured it out :

<?php  echo CHtml::activeDropDownList($products,'categoryID', CHtml::listData(categories::model()->findAll() , 'id', 'name') ); ?>

Oh the joy of learning a new framework. I will get there.  :)

Thanks, qiang for you assistance.