public function loadModel($id) { if (($model = GoodImage::model()->findByPk($id)) === null) { throw new CHttpException(404, 'Страница не найдена'); } return $model; }
/** * Builds html code with image list with checkboxes * @param string $size image size * @return string html code with images and chekboxes */ public function GetGoodImagesWithCheckbox($size = null) { $images = GoodImage::model()->findAllByAttributes(array('good_id' => $this->id)); $html = ''; foreach ($images as $image) { $name = 'Good[updatedimage][' . $image->id . ']'; if (is_null($size)) { $html .= CHtml::checkBox($name, FALSE) . CHtml::image('/images/goods/' . $image->image); } else { $html .= CHtml::checkBox($name, FALSE) . CHtml::image('/images/goods/' . $size . '_' . $image->image); } } return $html; }
/** * Deletes a particular model. * If deletion is successful, the browser will be redirected to the 'index' page. * @param integer $id the ID of the model to be deleted */ public function actionDelete($id) { if (Yii::app()->request->isPostRequest) { // we only allow deletion via POST request $images = GoodImage::model()->findAllByAttributes(array('good_id' => $id)); if (isset($images)) { foreach ($images as $image) { $image->delete(); } } if (Yii::app()->params['server'] == CAlexHelper::DEVELOPMENT) { $this->loadModel($id)->delete(); } // if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser if (!isset($_GET['ajax'])) { $this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin')); } } else { throw new CHttpException(400, 'Invalid request. Please do not repeat this request again.'); } }