protected function findModel($id) { if (($model = Block::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
public function run() { $block = \hass\area\models\Block::findByIdOrSlug($this->slug); $widget = $block["widget"]; $this->widgetOptions["model"] = $block; $result = $widget::widget($this->widgetOptions); return $result; }
public function getBlocks() { if (!empty($this->blocks)) { $query = Block::find()->where(['block_id' => $this->blocks])->orderBy([new \yii\db\Expression('FIELD (block_id, ' . implode(', ', $this->blocks) . ')')]); return $query->all(); } return []; }
public function actionUpdateBlocksCreate() { $id = \Yii::$app->getRequest()->post("id"); $blocks = \Yii::$app->getRequest()->post("blocks"); $block = \Yii::$app->getRequest()->post("block"); $model = $this->findModel($id); $model->blocks = $blocks; $block = Block::findOne($block); $block->used = BooleanEnum::TRUE; if ($model->save() && $block->save()) { return $this->renderJsonMessage(true, "更新成功"); } else { return $this->renderJsonMessage(true, "更新失败"); } }