protected function findModel($id) { if (($model = Fragment::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
public function actionUpdate($id, $fraid = null) { $model = $this->findModel($id); $fraid = $model->fragment_id; if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['index', 'fraid' => $fraid]); } else { $locals = []; $locals['model'] = $model; $locals['currentFragment'] = Fragment::findOne($fraid); return $this->render('update', $locals); } }
public static function getFragmentData($fraid, $other = [], $withFragment = false) { $query = null; // $query=Fragment1Data::find(); $fragment = Fragment::findOne($fraid); if ($fragment == null) { return []; } $type = $fragment->type; if ($type == 1) { $query = Fragment1Data::find(); } else { if ($type == 2) { $query = Fragment2Data::find(); } else { if ($type == 3) { $query = Fragment3Data::find(); } } } if ($query == null) { return []; } $query->where(['fragment_id' => $fraid]); if (isset($other['where'])) { $query->andWhere($other['where']); } if (isset($other['order'])) { $query->orderBy($other['where']); } else { $query->orderBy('sort_num desc'); } if (isset($other['offset']) && is_integer($other['offset'])) { $query->offset($other['offset']); } if (isset($other['limit']) && $other['limit']) { $query->limit($other['limit']); } $ret = $query->all(); if ($type === 3) { $temp = []; foreach ($ret as $row) { $item = self::getContentByChannel($row['channel_id'], ['where' => 'id=' . $row['content_id']]); if (empty($item)) { continue; } $temp[] = $item[0]; } $ret = $temp; } if ($withFragment) { return [$fragment, $ret]; } else { return $ret; } }