protected function afterDelete() { parent::afterDelete(); ItemsTags::model()->deleteAll('item_type=' . ItemsTags::MUSIC_TYPE . ' and item_id=' . (int) $this->id); }
<td>出生地</td> <td><?php echo CHtml::encode($model->native_place); ?> </td> </tr> <tr> <td colspan="2"><?php echo $model->intro; ?> </td> </tr> <tr> <td>标签 </td> <td><?php $rows = ItemsTags::returnTags(ItemsTags::ARTIST_TYPE, $model->id); foreach ($rows as $row) { echo CHtml::link(CHtml::encode($row['name']), array('tag/view', 'id' => $row['id']), array('target' => '_blank')) . " "; } ?> </td> </tr> </table> <h2>热门歌曲</h2> <?php $dataProvider = new CActiveDataProvider('Music', array('criteria' => array('condition' => 't.proved=' . Music::STATUS_PROVED . ' AND t.artist_id=' . $model->id, 'with' => array('album')), 'pagination' => array('pageSize' => 8))); $this->widget('zii.widgets.CListView', array('dataProvider' => $dataProvider, 'itemView' => '_music', 'summaryText' => '')); ?> <h2>所有专辑</h2> <?php
<td><?php echo CHtml::encode($model->pub_time); ?> </td> </tr> <tr> <td>唱片公司</td> <td><?php echo CHtml::encode($model->company); ?> </td> </tr> <tr> <td>标签</td> <td><?php $rows = ItemsTags::returnTags(ItemsTags::ALBUM_TYPE, $model->id); echo '<pre>'; foreach ($rows as $row) { echo CHtml::link(CHtml::encode($row['name']), array('tag/view', 'id' => $row['id']), array('target' => '_blank')) . " "; } ?> </td> </tr> <tr> <td colspan="3"><p>专辑介绍:</p><?php echo $model->introduction; ?> </td> </tr> </table> <h2>所有歌曲</h2>
public function addTags($tags, $itemtype, $itemid) { if (empty($tags)) { return; } foreach ($tags as $name) { $tag = NULL; $tag = Tag::model()->find("name='{$name}'"); if (!$tag) { //未存在,添加 $tag = new Tag(); $tag->name = $name; $tag->save(); } $newItemTag = new ItemsTags(); $newItemTag->item_type = $itemtype; $newItemTag->item_id = (int) $itemid; $newItemTag->tag_id = (int) $tag->id; $newItemTag->save(); } }