/** * 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 LiikuntaSuosikit the loaded model * @throws CHttpException */ public function loadModel($id) { $model = LiikuntaSuosikit::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
<div class="panel-body"> <div class="table-responsive"> <table class="table table-hover tabTuotteet"> <tr> <th>Laji</th> <th></th> </tr> <?php foreach ($data as $model) { echo ' <tr class="link viivat" id="' . $model->id . '" laji="' . $model->laji . '" value="' . $model->value . '"> <td>' . $model->laji . '</td>'; $criteria = new CDbCriteria(); $criteria->condition = " liikunta_paivakirja_id='" . $model->id . "' AND user_id='" . Yii::app()->user->id . "' "; $s = LiikuntaSuosikit::model()->find($criteria); if (isset($s->id)) { echo '<td><b class="onSuosiki fa fa-star" title="Poista suosikeista" style="font-size:150%;color:#FF9900" suID="' . $s->id . '" forID="' . $model->id . '"></b></td>'; } else { echo '<td><b class="tahti fa fa-star-o" title="Lisää suosikkeihin" style="font-size:150%" forID="' . $model->id . '"></b></td>'; } echo '</tr>'; } ?> </table> </div> </div> </div> <?php }
public function actionRemove_suosiki() { if (isset($_POST['sivu']) and $_POST['sivu'] == 'ruoka') { RuokaSuosikit::model()->deletebypk($_POST['id']); } elseif (isset($_POST['sivu']) and $_POST['sivu'] == 'liikunta') { LiikuntaSuosikit::model()->deletebypk($_POST['id']); } echo 'poistettu'; }