How to add delete button
Problem Add Delete button in AdminFile/update under New Attribute Create actionDeleteAttr Pass Behat tests How Add Delete button in /protected/adminFile/_form.php <tbody> <?php foreach($model->fileAttributes as $fa) { ?> <tr class="row-edit-<?= $fa->id ?>"> <td> <?= $fa->attribute->attribute_name ?> </td> <td> <?= $fa->value ?> </td> <td> <?= $fa->unit ? $fa->unit->name : '' ?> </td> <td><a role="button" class="btn btn-edit js-edit" data="<?= $fa->id ?>">Edit</a></td> <td><a role="button" class="btn js-delete" name="delete_attr" data="<?= $fa->id ?>">Delete</a></td> </tr> <?php } ?> </tbody> <script> $('.js-delete').click(function (e) { e.preventDefault(); id = $(this).attr('data'); console.log(id); row = $('.row-edit-' + id); console.log(row); if (id) { $.post('/adminFile/deleteAttr', { 'id': id }, function(result) { if (result) { // console.log(result); } }, 'json'); } window.location.reload(); }) </script> Create actionDeleteAttr in /controller/AdminFileController.php public function actionDeleteAttr() { if (!Yii::app()->request->isPostRequest) throw new CHttpException(404, "The requested page does not exist."); if (isset($_POST['id'])) { $attribute = FileAttributes::model()->findByPk($_POST['id']); if ($attribute) { $attribute->delete(); Yii::app()->end(); } } } Create admin-file.feature @admin-file @issue-457 Feature: An admin user can edit and delete attribute in admin file page As an admin user I can edit/delete attribute So that I can associate various attributes to files Background: Given Gigadb web site is loaded with production-like data @ok @issue-457 @javascript Scenario: Guest user cannot visit admin file update page Given I am not logged in to Gigadb web site When I go to "/adminFile/update/" Then I should see "Login" @ok @issue-457 @javascript Scenario: Sign in as admin and visit admin file update page and see New Attribute, Edit, Delete buttons Given I sign in as an admin When I am on "/adminFile/update/id/13973" Then I should see a button "New Attribute" And I should see a button input "Edit" And I should see a button input "Delete" @ok @issue-457 @javascript Scenario: Sign in as admin to delete attribute Given I sign in as an admin And I am on "/adminFile/update/id/13973" And I should see a button input "Delete" When I press "Delete" And I wait "3" seconds Then I should not see a button "Delete" Run behat test with Database set up 4.1 only accptance test #!/usr/bin/env bash set -e -u ./tests/acceptance #./tests/unit_functional #./tests/coverage 4.2 change tag to @wip ...