Commit f000644637691d6a387c89246e9652afeca6788c
1 parent
33d742d9
- comments
- delete books
Showing
3 changed files
with
26 additions
and
1 deletions
Show diff stats
backend/controllers/BookController.php
... | ... | @@ -143,6 +143,20 @@ |
143 | 143 | return $this->redirect([ 'index' ]); |
144 | 144 | } |
145 | 145 | |
146 | + public function deleteModel($id) | |
147 | + { | |
148 | + $book = Book::find() | |
149 | + ->where( | |
150 | + [ | |
151 | + 'id' => $id, | |
152 | + ] | |
153 | + ) | |
154 | + ->one(); | |
155 | + | |
156 | + | |
157 | + return $book->delete(); | |
158 | + } | |
159 | + | |
146 | 160 | public static function removeDirectory($dir) |
147 | 161 | { |
148 | 162 | if ($objs = glob($dir . "/*")) { | ... | ... |
backend/views/comment/_form.php
... | ... | @@ -29,7 +29,11 @@ JS; |
29 | 29 | <div class="feedback-form"> |
30 | 30 | |
31 | 31 | <?php $form = ActiveForm::begin(); ?> |
32 | - <?=$model->book->title?> | |
32 | + <?php | |
33 | + if ($model->entityObject !== null){ | |
34 | + echo $model->entityObject->title; | |
35 | + } | |
36 | + ?> | |
33 | 37 | |
34 | 38 | <?= $form->field($model, 'name') |
35 | 39 | ->textInput([ 'maxlength' => true ]) ?> | ... | ... |
common/models/Comment.php
... | ... | @@ -127,4 +127,11 @@ |
127 | 127 | public function getActiveComments(){ |
128 | 128 | return $this->getComments()->where(['status' => true]); |
129 | 129 | } |
130 | + | |
131 | + public function getEntityObject(){ | |
132 | + if ($this->entity !== null){ | |
133 | + return $this->hasOne($this->entity, ['id' => 'entity_id']); | |
134 | + } | |
135 | + return null; | |
136 | + } | |
130 | 137 | } | ... | ... |