2012-01-02 2 views
1

프레임 워크를 사용하여 블로그를 만드는 데있어 매우 기본적인 (그러나 화려한) CakePHP 튜토리얼을 따라합니다.CakePHP에서 jQuery 애니메이션 'delete entry'효과 사용 하시겠습니까?

나는 모험심이 많으므로 이것을 사용해보십시오. Animated AJAX Record Deletion Using jQuery 효과는 my Delete entry script입니다.

내가 어떻게이 작업을 수행 할 수 있는지 설명 할 수 있습니까?

+0

:-) 여기에 어떤 포인터에 대한

많은 감사는 경고 :이 cake2 및하지만 POSTLINK() 작동하지 않습니다. 적 최첨단 버전을 사용할 계획이라면 :) – mark

+0

그냥 궁금 해서요, 케이크 2.0에서는 작동하지 않겠습니까? – Mo3z

+0

당신의 대답에 그것을 추가해야합니다 - 당신은 mcgarriers가 cake <2.0을 사용하고 있다고 가정하고 있습니다 (아마 맞을지라도). cake2는 기본 게시물 링크를 사용하여 약간 더 어렵습니다. – mark

답변

2
//Your view action: 
<?php 

function index() { 
    //Provide your pagination info.. 
    $this->set('entries', $this->paginate()); 
} 
?> 

//Your delete action: 
<?php 

function delete($id) { 
    $this->autoRender = false; 
    if ($this->Blog->delete($id)) { 
     $response = array("success" => true); 
    } else { 
     $response = array("success" => false); 
    } 
    return json_encode($response); 
} 
?> 

//Your index.ctp 
..... 
<?php foreach ($entries as $entry): ?> 
    <div class="record"> 
     <a href="<?php echo $this->Html->url(array("controller" => "blog", "action" => "delete", $entry['Blog']['id'])) ?>" class="delete">Delete</a> 
     <strong><?php echo $entry['Blog']['title'] ?></strong> 
    </div> 
<?php endforeach; ?> 

//Your Javascript 
<script type="text/javascript"> 
    $(document).ready(function() { 
     $('a.delete').click(function(e) { 
      var __this = this; 
      e.preventDefault(); 
      var parent = $(this).parent(); 
      $.ajax({ 
       type: 'get', 
       url: $(__this).attr("href"), 
       beforeSend: function() { 
        parent.animate({'backgroundColor':'#fb6c6c'},300); 
       }, 
       success: function(response) { 
        //Changed here 
        response = $.parseJSON(response);//console.log(response); 
        if(response.success){ 
         parent.slideUp(300,function() { 
          parent.remove(); 
         }); 
        }else{ 
         alert("Failed to delete message"); 
         parent.animate({'backgroundColor':'#fff'},100);//Restore your background back 
        } 
       } 
      }); 
     }); 
    }); 
</script> 
+0

자세한 답변을 해주신 것에 대해 많은 감사드립니다. 나는 여러 가지 변화를 일으켰고 하나의 문제를 제외하고는 그것을 변화 시켰습니다. '삭제'를 클릭하면 배경이 빨간색으로 설정되고 '경고 메시지에 메시지를 삭제하지 못했습니다.'라는 메시지가 표시되지만이 메시지를 닫으면 메시지가 실제로 삭제됩니다. 현재 생각한 내용을 게시 할 수 있습니까? – michaelmcgurk

+1

느낀다 .. – Mo3z

+0

index.ctp - http://pastie.org/3118824, 포스트 컨트롤러 - http://pastie.org/3118829 - 위의 코드를 사용하여 – michaelmcgurk

관련 문제