Custom Queries (DAO) in model? component? or even a better place?

Hi there,

I’m new to YII. I hope that someone can help me with this one.

In YII you have the ActiveRecord to manipulate tables in the database. You also have the DOA

for writing your own queries.

I was wondering if i want to execute for example a SELECT * FROM users query, where do i have to put this?

I am used to put queries into a Model (i was using Codeigniter). I see a lot of examples HOW to build Sql queries, but i can’t see WHERE those commands are in the right place.

I hope someone can tell me this :rolleyes:

Thanks in advance

[color="#006400"]/* Moved from Miscellaneous forum to Yii 1.1 general discussion */[/color]

usually in a controller.

In model, you can define higher level stuff like relations, scopes, validations rules and so on

Thanks for your reply.

Meanwhile i kept searching for an answer. at the page http://www.yiiframework.com/doc/guide/1.1/en/basics.best-practices#model i found that a controller should avoid containing embedded SQL statements, which are better kept in models.

So this sounds like if the model is a better place to hold Sql statements.

Yes, it is better practice. IMO.

Ok, good to know …