got stuck in middle....

Hi guys,

I’m newbie to Yii and this is my first time I choose any framework and start working on it based on a little OOP knowledge.

I got some how manage my application which is going on right direction but got stuck in middle of my project, my problem is here.

I got three tables.




City 

-----

id

cityname

...


Post

-----

id

title

content

city_id

....


comment

-------

id

content

post_id




     City Model relation

     -------------------

     return array(

          'city' => array(self::HAS_MANY, 'Post', 'city_id'),,

     );


     Post Model relation

     -------------------

     return array(

	  'city' => array(self::BELONGS_TO, 'City', 'city_id'),

	  'comments' => array(self::HAS_MANY, 'Comment', 'post_id'),

	  'commentCount' => array(self::STAT, 'Comment', 'post_id'),		

     );


     

     Comment Model relation

     ----------------------

     return array(

          'post' => array(self::BELONGS_TO, 'Post', 'post_id'),

     );



My desired goal


From main index page a user select a City from dropdown and then it will bring up the first saved Post not all and based on that selected Post display all post related fields on index page and it will count all Comments and show that commentCount on same index page.

My DefaultController is ‘Post’ at the moment, should I change it to ‘City’.

Please guide me into this my first application, I’ll highly appreciate all you guys help.

Saad

You’ve not specified the problem you have so the only think I can recommend is to read these:

http://www.yiiframework.com/doc/guide/database.ar

http://www.yiiframework.com/doc/guide/database.arr

Hi,

thanks for your reply and those link and in regards to your question “You’ve not specified the problem you have so” so here is what I would like to do which I don’t know how to do it.

Task-1 : From main index page I would like to select a "City Name" from dropdown and then it will go and find any "Post" in post table for that particular selected City Name if found then display the first saved Post means display one row not all if there are more then one for that city.

Task-2 : If there is any "Comments" in comments table related to selected post will count all Comments and show that commentCount on same index page some where.

My DefaultController is ‘Post’ at the moment, should I change it to ‘City’.

Please do have a look to my City, Post & Comment model relation if any correction need guide me that as well and how to achieve the "Task-1 & Task-2".