Example #1
0
 /**
  * This is the default 'index' action that is invoked
  * when an action is not explicitly requested by users.
  */
 public function actionIndex()
 {
     $ads = Ad::model()->findAll();
     $posts = Post::model()->findAll(new CDbCriteria(array('limit' => 5, 'order' => 'id desc')));
     $hotCategories = Category::model()->hot()->level(2)->limit(3)->findAll();
     $hotItems = array();
     foreach ($hotCategories as $hotCategory) {
         $hotItems[$hotCategory->name] = Item::getItemsByCategory($hotCategory, 4);
     }
     $newCategories = Category::model()->new()->level(2)->limit(3)->findAll();
     $newItems = array();
     foreach ($newCategories as $key => $newCategory) {
         if ($key == 0) {
             $newItems[$newCategory->name] = Item::getItemsByCategory($newCategory, 7);
         } else {
             $newItems[$newCategory->name] = Item::getItemsByCategory($newCategory, 8);
         }
     }
     Yii::app()->params['ads'] = $ads;
     //        $newItems[0] = array_slice($newItems[0], 7);
     $this->render('index', array('ads' => $ads, 'posts' => $posts, 'hotCategories' => $hotCategories, 'hotItems' => $hotItems, 'newCategories' => $newCategories, 'newItems' => $newItems));
 }