久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

引導程序 3 確認刪除 cakephp 中的模式

bootstrap 3 confirm delete modal in cakephp(引導程序 3 確認刪除 cakephp 中的模式)
本文介紹了引導程序 3 確認刪除 cakephp 中的模式的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我有一個記錄表,其中每一行都有一個刪除鏈接.您會找到用于刪除操作的 cakephp :

公共函數刪除($id){如果 ($this->request->is('get')) {拋出新的 MethodNotAllowedException();}如果 ($this->Category->delete($id)) {$this->Session->setFlash('Votre élément a été supprimé.','default',array(),'success');返回 $this->redirect(array('action' =>'index'));}}

因此,當我單擊刪除按鈕時,會顯示一個原始 javascript 確認對話框以確認視圖中的刪除操作.這是一個包含刪除鏈接的 index.ctp :

<table class="table table-striped table-condensed table-bordered"><tr><th>title</th><th>動作</th></tr><?php foreach ($categorys as $category): ?><tr><td><?php echo $category['Category']['title'];?></td><td><?phpecho $this->Html->link('View',數組('控制器' => '類別', '動作' => '視圖', $category['Category']['id']),數組('class' => 'btn btn-info btn-sm active'));?><?phpecho $this->Html->link('編輯', array('action' => 'edit', $category['Category']['id']),數組('class' => 'btn btn-primary btn-sm active'));?><?phpecho $this->Form->postLink('刪除',array('action' => 'delete', $category['Category']['id']),array('confirm' => '你真的要刪除這個元素嗎?','class' => 'btn btn-danger btn-sm active'));?></td></tr><?php endforeach;?><?php unset($category);?>

所以對于我想要的后鏈接,當我點擊鏈接時,它會向我顯示一個引導程序確認模式,如下所示:

 <div class="modalfade" id="ConfirmDelete" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"><div class="modal-dialog modal-sm"><div class="modal-content"><div class="modal-header"><button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button><h4 class="modal-title" id="myModalLabel">類別刪除</h4>

<div class="modal-body">你真的要刪除這個元素嗎?

<div class="modal-footer"><button type="button" class="btn btn-default" data-dismiss="modal">關閉</button><a class="btn btn-danger 危險">確認</a>

誰能幫我使用cake php的jshelper來創建一個引導模式對話框而不是默認的對話框.

謝謝.

解決方案

我編輯我的答案并改進代碼

在您的索引頁面上而不是 postLink,創建一個按鈕或鏈接來調用模態,即

Html->link($this->Html->tag('i', '', array('class' => 'glyphicon glyphicon-trash')),'#',大批('class'='btn btn-danger btn-confirm','數據切換'=>'模態','數據目標' =>'#確認刪除','數據動作'=>路由器::網址(數組('action'=>'delete',$category['Category']['id'])),'逃脫' =>錯誤的),錯誤的);?>

在你的模態中添加 postLink 沒有確認消息,而不是把消息放在 false:

Form->postLink('確認',數組('動作' => '刪除'),array('class' => 'btn btn-danger btn-sm active'),錯誤的,));?>

在bootstrap.js之后添加這段js代碼

$(document).ready(function() {$(".btn-confirm").on("click", function () {var action = $(this).attr('data-action');$("form").attr('action',action);});});

或者按照user1655410的建議添加這個js代碼

$('#ConfirmDelete').on('show.bs.modal', function(e) {$(this).find('form').attr('action', $(e.relatedTarget).data('action'));});

hi i have a table of records where there's a delete link for every row.Her you will find cakephp for the delete action :

public function delete($id){

        if ($this->request->is('get')) {
            throw new MethodNotAllowedException();
        }

        if ($this->Category->delete($id)) {
            $this->Session->setFlash( 'Votre élément a été supprimé.','default',array(),'success');
            return $this->redirect(array('action' => 'index'));
        }

    }

so when i click on the delete button a raw javascript confirm dialog box is diplayed to confirm the action of the deletion in the view. here's an index.ctp containing the delete link :

<!--table content-->
  <table class="table table-striped table-condensed table-bordered">
    <tr>
        <th>title</th>
        <th>Actions</th>
    </tr>

    <?php foreach ($categorys as $category): ?>
    <tr>
        <td><?php echo $category['Category']['title']; ?></td>
        <td>
            <?php
            echo $this->Html->link('View',
                                   array('controller' => 'categories', 'action' => 'view', $category['Category']['id']),
                                   array('class' => 'btn btn-info btn-sm active')
                                   ); ?>
            <?php
            echo $this->Html->link(
                'Edit', array('action' => 'edit', $category['Category']['id']),
                          array('class' => 'btn btn-primary btn-sm active')
            );
            ?>
            <?php
            echo $this->Form->postLink(
                'Delete',
                array('action' => 'delete', $category['Category']['id']),
                array('confirm' => 'Do you want really to delete thi element?','class' => 'btn btn-danger btn-sm active')
            );
            ?>
        </td>
    </tr>
    <?php endforeach; ?>
    <?php unset($category); ?>
  </table>

so for the postlink i want when i click on the link it will show me a bootstrap confirmation modal like this :

 <!-- Modal -->
    <div class="modal fade" id="ConfirmDelete" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog modal-sm">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                    <h4 class="modal-title" id="myModalLabel">Category deletion</h4>
                </div>
                <div class="modal-body">
                    Do you  really want  to delete thi element?
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                    <a  class="btn btn-danger danger">Confirm</a>
                </div>
            </div>
        </div>
    </div>

can someone help me to use the jshelper of the cake php to create a bootstrap modal dialog instead of the default one.

Thank you.

解決方案

I edit my answer and improve code

On your index page instead postLink, create a button or link that will call the modal, ie

<?php 
echo $this->Html->link(
    $this->Html->tag('i', '', array('class' => 'glyphicon glyphicon-trash')), 
    '#', 
    array(
       'class'=>'btn btn-danger btn-confirm',
       'data-toggle'=> 'modal',
       'data-target' => '#ConfirmDelete',
       'data-action'=> Router::url(
          array('action'=>'delete',$category['Category']['id'])
       ),
       'escape' => false), 
false);
?>

In your modal add postLink without confirmation message, instead of the message put false:

<?php
    echo $this->Form->postLink(
         'Confirm',
            array('action' => 'delete'),
            array('class' => 'btn btn-danger btn-sm active'),
            false,
         )
        );
        ?>

add this js code after bootstrap.js

$(document).ready(function() {
  $(".btn-confirm").on("click", function () {
     var action = $(this).attr('data-action');
     $("form").attr('action',action);
});
});

or as suggested by user1655410 add this js code

$('#ConfirmDelete').on('show.bs.modal', function(e) {
    $(this).find('form').attr('action', $(e.relatedTarget).data('action'));
});

這篇關于引導程序 3 確認刪除 cakephp 中的模式的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Cannot use #39;Object as class name as it is reserved Cake 2.2.x(不能使用 Object 作為類名,因為它是保留的 Cake 2.2.x)
Session is lost after an OAuth redirect(OAuth 重定向后會話丟失)
Pagination Sort in Cakephp 3.x(Cakephp 3.x 中的分頁排序)
CakePHP Shared core for multiple apps(CakePHP 多個應用程序的共享核心)
Login [ Auth-gt;identify() ] always false on CakePHP 3(在 CakePHP 3 上登錄 [ Auth-identify() ] 始終為 false)
Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 87 bytes)(致命錯誤:允許的內存大小為 134217728 字節已用盡(嘗試分配 87 字節))
主站蜘蛛池模板: 欧美日韩在线一区二区 | 久久精品视频12 | 日韩av免费看 | 国产美女在线观看 | 日韩美女一区二区三区在线观看 | 亚洲一区二区在线播放 | 六月成人网 | 欧美一级二级视频 | 欧美精品三区 | 精品1区2区 | 亚洲一区三区在线观看 | 欧美一级片 | 成人在线视频观看 | 国产女人叫床高潮大片免费 | 国产精品一区二区在线 | 国产黄色在线 | 在线一级片 | 国产精品99视频 | 久久99精品视频 | 日韩国产中文字幕 | 中文字幕av亚洲精品一部二部 | 91天堂网 | 亚洲欧美网站 | 日韩在线免费看 | 国产黄色电影 | 国产视频中文字幕 | 噜噜噜噜狠狠狠7777视频 | 日韩国产欧美一区 | 久久99精品久久久水蜜桃 | 一区二区三区免费 | 日日噜噜噜夜夜爽爽狠狠视频97 | 二区不卡 | 一区二区三区四区国产 | 91在线看| 一二三四在线视频观看社区 | 中文字幕一页二页 | 国产一区二区三区在线 | 国产一区中文字幕 | 熟女毛片| 国产精品一区二区精品 | 国产精品久久久爽爽爽麻豆色哟哟 |