public function actionIndex() { if (isset($_POST['ajax'])) { $slideShows = Slideshow::model()->findAll(); $images = array(); if ($slideShows) { foreach ($slideShows as $slideShow) { $images[] = $slideShow->imageLink; } echo json_encode($images); } } else { $newProducts = NewProducts::model()->findAll(); $hotProducts = HotProducts::model()->findAll(array("limit" => 17)); $amthucs = Amthuc::model()->findAll(array("order" => 'id DESC', "limit" => 4)); if ($newProducts || $hotProducts) { $newProduct = array(); foreach ($newProducts as $newProduct1) { $product = Products::model()->findByPk($newProduct1->product_id); if ($product) { $newProduct[$newProduct1->id] = $product; } } foreach ($hotProducts as $key => $value) { $product = Products::model()->find('id=:product_id', array(':product_id' => $value->product_id)); if ($product) { $products[] = $product; } } if ($newProduct && $products || $amthucs) { $this->render('index', array('newProduct' => $newProduct, 'products' => $products, 'amthucs' => $amthucs)); } else { $this->render('index'); } } } }
public function run() { $model = Slideshow::model()->findAll(); $this->render('slideshow', array('model' => $model)); }
/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param integer $id the ID of the model to be loaded * @return Slideshow the loaded model * @throws CHttpException */ public function loadModel($id) { $model = Slideshow::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }