/** * Deletes a particular model. * If deletion is successful, the browser will be redirected to the 'admin' 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 $file_sample = FileSample::model()->findByAttributes(array('file_id' => $id))->delete(); $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.'); } }
<h1>View File #<?php echo $model->id; ?> </h1> <? if (Yii::app()->user->checkAccess('admin')) { ?> <div class="actionBar"> [<?php echo MyHtml::link('Manage Files', array('admin')); ?> ] </div> <? } ?> <?php $sample_id = FileSample::model()->find('file_id=:file_id', array(':file_id' => $model->id)); if (isset($sample_id)) { $sample_name = Sample::model()->find('id=:id', array(':id' => $sample_id->sample_id)); } $name = "Not Set"; if (isset($sample_id) && isset($sample_name)) { $name = $sample_name->name; } $this->widget('zii.widgets.CDetailView', array('data' => $model, 'attributes' => array('id', 'dataset_id', 'name', 'location', 'extension', 'size', 'description', 'date_stamp', 'format_id', 'type_id', array('name' => 'Sample', 'value' => $name))));