public function saveSort($sort) { // $blocks_id=array(); $this->sort = $sort; //получаем массив значений значений $blocks_id = explode(':', $this->sort); //print_r($blocks_id); //die(); /* $models = Block::find() ->leftJoin('landing_block', '`landing_block`.`block_id` = `block`.`block_id`') ->where(['not in', 'landing_block.landing_id', $blocks_id]) ->orWhere(['landing_block.landing_id' => NULL]); return $models; */ // Делаем невидимыми все блоки лендинга $blocks = Block::find()->where(['landing_id' => $this->landing_id])->all(); foreach ($blocks as $block) { $block->visible = 0; $block->save(); } $i = 1; foreach ($blocks_id as $block_id) { $landingBlock = Block::findOne($block_id); // ->where(['block_id' => $block_id,'landing_id' => $this->landing_id]) // ->one(); if ($landingBlock !== null) { } else { die('Ошибка 678'); //$landingBlock = new Block(); //$landingBlock->type_id = $block_id; //$landingBlock->landing_id = $this->landing_id; } $landingBlock->visible = 1; $landingBlock->sort = $i; $landingBlock->save(); $i++; } }
/** * Finds the Block model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Block the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Block::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }