/** * 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. */ public function loadModel() { if ($this->_model === null) { if (isset($_GET['id'])) { $this->_model = ArtistArea::model()->findbyPk($_GET['id']); } if ($this->_model === null) { throw new CHttpException(404, '请求的页面不存在。'); } } return $this->_model; }
public function run($region = 1, $type = 2) { $criteria = new CDbCriteria(); $criteria->condition = 'proved=:proved'; $criteria->params = array(':proved' => Artist::STATUS_PROVED); $criteria->order = "sort ASC,add_time DESC"; $criteria->group = 'sort,id'; $region = (int) $region; $type = (int) $type; $criteria->addSearchCondition('area_id', $region); $criteria->addSearchCondition('type_id', $type); $rawData = Artist::model()->findAll($criteria); $value = Yii::app()->cache->get('ARTISTS_' . $region . '_' . $type); if ($value === false) { $dataProvider = new CArrayDataProvider($rawData, array('id' => 'artist', 'pagination' => array('pageSize' => 500))); Yii::app()->cache->set('ARTISTS_' . $region . '_' . $type, $dataProvider, 10); } else { $dataProvider = $value; } $regionData = ArtistArea::model()->findByPk($region); $typeData = ArtistType::model()->findByPk($type); $this->render('index', array('dataProvider' => $dataProvider, 'region' => $region, 'type' => $type, 'regionData' => $regionData, 'typeData' => $typeData)); }
<ul> <?php $artistAreas = ArtistArea::model()->findAll(); foreach ($artistAreas as $area) { echo '<li>'; echo '<ul>'; echo '<b>' . $area->name . '</b>'; echo '<li>'; echo CHtml::link('女歌手', array('artist/index', 'region' => $area->id, 'type' => 2)); echo '</li>'; echo '<li>'; echo CHtml::link('男歌手', array('artist/index', 'region' => $area->id, 'type' => 1)); echo '</li>'; echo '<li>'; echo CHtml::link('乐队组合', array('artist/index', 'region' => $area->id, 'type' => 3)); echo '</li>'; echo '</ul>'; echo '</li>'; } ?> </ul>
public static function getArtistNavData() { $data = array(); $artistAreas = ArtistArea::model()->findAll(); $c = count($artistAreas); for ($i = 0; $i < $c; $i++) { $data[$i]['text'] = $artistAreas[$i]->name; $data[$i]['expanded'] = true; $data[$i]['hasChildren'] = true; $data[$i]['children'] = array(array('text' => CHtml::link('女歌手', array('artist/index', 'region' => $artistAreas[$i]->id, 'type' => 2))), array('text' => CHtml::link('男歌手', array('artist/index', 'region' => $artistAreas[$i]->id, 'type' => 1))), array('text' => CHtml::link('乐队组合', array('artist/index', 'region' => $artistAreas[$i]->id, 'type' => 3)))); } return $data; }