/** * @param $id * @return string */ public function run($id) { /** @var Image $file */ $file = Image::findOne(['id' => $id]); $deleted = $file->delete(); return $this->getResponse($file, $deleted); }
/** * @param $id * @return string * @throws NotFoundHttpException */ public function actionDelete($id) { /** @var Image $image */ $image = Image::findOne(['id' => $id]); if (!$image) { throw new NotFoundHttpException(); } $image->delete(); return Json::encode(1); }
/** * @throws \yii\db\Exception */ public function saveAttachments() { $data = \Yii::$app->request->post($this->owner->formName()); $attachments = null; if (isset($data['images'])) { $attachments = $data['images']; } if (isset($data['image'])) { $attachments = $data['image']; } if (isset($attachments)) { $this->deleteAttachments(); if (is_array($attachments)) { foreach (array_keys($attachments) as $sort => $fileId) { /** @var Image $image */ $image = Image::findOne(['id' => $fileId]); if ($image) { $this->owner->getDb()->createCommand()->insert($this->junctionTable, ['file_id' => $fileId, 'model' => $this->modelShortName, 'item_id' => $this->owner->getPrimaryKey(), 'sort' => $sort + 1])->execute(); } } } } }