0
私はCakePHP 3.3を使用していますが、users
というリストがあり、特定のユーザーの削除をキャンセルすることを確認する前にSweetAlertの確認ボックスを表示します。CakePHP 3.3 SweetAlertを使用してレコードの削除を確認します
これは、ユーザーのリストが含まれていsrc/Template/Users/index.ctp
ファイルからの抜粋です:その後、私は私のsrc/Template/Layout/default.ctp
でスクリプトを持って
<tbody>
<?php foreach ($users as $user): ?>
<tr>
<td><?= $this->Html->image('../'.$user->avatar, ['class' => 'img-avatar']); ?></td>
<td><?= h($user->username) ?></td>
<td><?= h($user->role) ?></td>
<td><?= h($user->created) ?></td>
<td><?= h($user->modified) ?></td>
<td class="actions">
<span class="label label-default"><?= $this->Html->link(__('View'), ['action' => 'view', $user->id]) ?></span>
<span class="label label-default"><?= $this->Html->link(__('Edit'), ['action' => 'edit', $user->id]) ?></span>
<span class="label label-default"><?= $this->Form->postLink(__('Delete'), ['action' => 'delete', $user->id], ['confirm' => __('Are you sure you want to delete # {0}?', $user->id)]) ?></span>
</td>
</tr>
<?php endforeach; ?>
</tbody>
<button class="btn-del">DUMMY BUTTON</button>
:
<script>
document.querySelector('.btn-del').onclick = function(){
swal({
title: "Are you sure?",
text: "You will not be able to recover this imaginary file!",
type: "warning",
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: "Yes, delete it!",
closeOnConfirm: false
},
function(){
swal("Deleted!", "Your imaginary file has been deleted.", "success");
});
};
</script>
私はそれを使用して働いて、スクリプトを試してみましたDummy Button
ですが、削除するたびにindex.ctp
へのリダイレクトを使用して、user
レコードの削除を確認またはキャンセルできるように、どのように動作させるかわかりません。
申し訳ありません私はCakePHPとJSの初心者です&ありがとうございます。