public function actionRemoveAll() { $items = Yii::$app->request->post('items', []); if (!empty($items)) { $items = ContentBlock::find()->where(['in', 'id', $items])->all(); foreach ($items as $item) { $item->delete(); } } return $this->redirect(['index']); }
/** * preloads chunks with option preload = 1 * and push it to static array * @return array|void */ public static function preloadChunks() { if (is_null(static::$chunksByKey)) { $dependency = new TagDependency(['tags' => [ActiveRecordHelper::getCommonTag(ContentBlock::className())]]); static::$chunksByKey = ContentBlock::getDb()->cache(function ($db) { $chunks = ContentBlock::find()->where(['preload' => 1])->asArray()->all(); return ArrayHelper::map($chunks, 'key', 'value'); }, 86400, $dependency); } return static::$chunksByKey; }