/** * 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)); }
<?php //echo $form->textField($model,'type_id'); echo $form->dropDownList($model, 'type_id', ArtistType::getAll()); ?> <?php echo $form->error($model, 'type_id'); ?> </div> <div class="row"> <?php echo $form->labelEx($model, 'area_id'); ?> <?php //echo $form->textField($model,'area_id'); echo $form->dropDownList($model, 'area_id', ArtistArea::getAll()); ?> <?php echo $form->error($model, 'area_id'); ?> </div> <div class="row"> <?php echo $form->labelEx($model, 'sort'); ?> <?php echo $form->textField($model, 'sort', array('size' => 8, 'maxlength' => 8)); ?> <?php
/** * Loads the lookup items for the specified type from the database. * @param string the item type */ private static function loadItems() { self::$_itemsLookup = array(); $models = self::model()->findAll(); foreach ($models as $model) { self::$_itemsLookup[$model->id] = $model->name; } }
<?php $this->breadcrumbs = array('艺术家' => array('index'), '管理'); $this->menu = array(array('label' => '列出艺术家', 'url' => array('index')), array('label' => '增加艺术家', 'url' => array('create'))); Yii::app()->clientScript->registerScript('search', "\n\$('.search-button').click(function(){\n\t\$('.search-form').toggle();\n\treturn false;\n});\n\$('.search-form form').submit(function(){\n\t\$.fn.yiiGridView.update('artist-grid', {\n\t\tdata: \$(this).serialize()\n\t});\n\treturn false;\n});\n"); ?> <h1>管理艺术家</h1> <p> 你可以在每个搜索值之前输入一个对比符 (<b><</b>, <b><=</b>, <b>></b>, <b>>=</b>, <b><></b> 或 <b>=</b>) ,以指定对比如何完成。 </p> <?php echo CHtml::link('高级搜索', '#', array('class' => 'search-button')); ?> <div class="search-form" style="display:none"> <?php $this->renderPartial('_search', array('model' => $model)); ?> </div><!-- search-form --> <?php $this->widget('zii.widgets.grid.CGridView', array('id' => 'artist-grid', 'dataProvider' => $model->search(), 'filter' => $model, 'summaryText' => '这是 {start} 到 {end} 共 {count} 条记录', 'columns' => array(array('name' => 'type_id', 'value' => 'ArtistType::item($data->type_id)', 'filter' => ArtistType::items()), array('name' => 'area_id', 'value' => 'ArtistArea::item($data->area_id)', 'filter' => ArtistArea::items()), array('name' => 'name', 'type' => 'raw', 'value' => 'CHtml::link(CHtml::encode($data->name), $data->url)'), array('name' => 'proved', 'value' => 'Lookup::item("PROVED",$data->proved)', 'filter' => Lookup::items('PROVED')), array('name' => 'add_time', 'type' => 'datetime', 'filter' => false), array('class' => 'CButtonColumn'))));
<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; }