How To Make A Simple Application Using Dao?

Hi guys,

I’m new to yii and I feel get lost every time I try to make even a simple application. I have lot of question such as:

  1. Can I use the extension CActiveREcord while using DAO?

  2. How to display datagrid widget while using DAO and extension of CFormModel?

  3. Can anyone provide me a complete sample of yii application using DAO with extension of CFormModel. Please.I’ve been browsing all the forums of yii but no one provides a sample of yii application using DAO with model, controller and views.

Please help me to be enlighten in yii. Please guide me in proper way. Thank you.

Yes you can (in light of upcoming US elections… :) .

DAO are not related to AR, but you can combine the two. Just remember that when you perform some DAO query it doesn’t mean that the AR object that you have in your hand was saved or something. You’ll need to save() it.

One common example in which the two work together are transactions. You start a transaction with a DAO command, save several related AR models that you want to save all or nothing (in a try-catch block) followed by a ‘commit’ (see example in last link).

Basically, the grid is created comfortable in Yii with CGridView. The CGridView object will need a ‘data provider’ - which is exactly as it sounds - an object that will feed it with data (it needs to implement the interface IDataProvider). So I guess that your fetish to manual SQL queries could be exercised using an sql data provider :)

I don’t remember if the blog tutorial has this but in any case its an important yii-newcomer read: blog tutorial.

Also, when you feel comfortable enough, consult the wiki with questions. There’s a good chance that what you want is already documented there as a contributed article.

Last thing - future similar questions should go into the ‘general discussions’ forum, not this one.

Good luck!

[color="#006400"]/* Moved from Tips, Snippets and Tutorials to General Discussion … */[/color]

Thank you so much for this reply. I learn something new. :lol: