nbgerd
(Gerd)
January 29, 2011, 5:50pm
1
Hi all,
I’m Gerd a dutch programmer (mainly php and shell)
Recently i started ussing Yii and i must say: Wow what a great framework. Good work!
I think i get the yii basics and dont have any issues with simple apps in yii.
The questions i have is this:
How do i count the numbers of rows in my database table , for example
Select count(*) as viewed from mytabel WHERE viewed=‘Y’
How do i do this with yii? i already got my database model up.
I got a pretty large database with lots of tabels. do i really need to make a model for each tabel or can i make one for an entire database at once?
Greetz
Gerd
andy_s
(Arekandrei)
January 29, 2011, 6:14pm
2
How do i count the numbers of rows in my database table
MyModel::model()->countByAttributes(array('viewed'=>'Y'));
http://www.yiiframework.com/doc/api/1.1/CActiveRecord#countByAttributes-detail
I got a pretty large database with lots of tabels. do i really need to make a model for each tabel or can i make one for an entire database at once?
Each model corresponds to a single database table. You can generate all models at once using Gii model generator. Just type "*" in "Table Name" field.
1 Your first question is answered here: http://www.yiiframework.com/doc/guide/1.1/en/database.arr#statistical-query
2 I think is better to do so when updating individual data table but, you can create views and use those models only for display or reporting. Making just one Model to the whole database? how can you do that?
nbgerd
(Gerd)
January 29, 2011, 6:25pm
4
thanks for the quick responds guys.
i gues having a model for each tabel is important to make relations etc.
Will digg into it the next phew days.
foe_1
(foe#1)
January 30, 2011, 2:55am
5
Gerd, you might already now about Gii. If not take a look into it to create models, if needed crud too