protected function findModel($id)
 {
     if (($model = Block::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
示例#2
0
 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;
 }
示例#3
0
 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, "更新失败");
     }
 }