2016-04-11 13 views
0

1回のクリックで複数の行またはすべての行を削除したい。 しかし、私はそれを把握できません。どのように私は私のコードでこれを行うことができますか?期待される結果のために私のコードを編集してください。ここで複数の選択された行をphalconで削除する

は、選択のための私のjQueryは、削除処理を実行するコントローラにしてIDを取得するにはどのようにすべての行

[Jquery] 
function selectAll(status){ 
$('input[name=slId]').each(function(){ 
    $(this).prop('checked', status); 
}); 
} 

のですか?私のjqueryはIDを送信しません、私はvar_dumpでテストして、NULLを表示します。

[Controller] 

public function deleteAction() 
{ 
    if($this->request->isPost()) 
    { 
     if($this->session->has('uname')) 
     { 
      $id = array(); 
      $id = $this->request->getPost('id'); 
      $data = Blogs::findByid($id); 
      if(!$data->delete()) 
      { 
       echo('Unable to Delete'); 
      } 
     } 
    } 
} 

[volt] 

{{ form('blog/delete', 'enctype': 'multipart/form-data') }} 
<table class="bloglist"> 
<thead> 
    <tr class="fbold"> 
      <td> 
{{check_field('checkbox','id':'sall','onclick':'selectAll(this.checked)')}}  </td> 
     <td>Title</td> 
     <td>Author</td> 
     <td>Views</td> 
     <td>PublishedOn</td> 
    </tr> 
</thead> 
<tbody> 
{%for all in ball %}  
    <tr class="zebra"> 
     <td>{{check_field('slId', 'class':'slId','id':all.id)}}</td> 
     <td class="tal">{{all.btitle}}</td> 
     <td>{{all.bauthor}}</td> 
     <td>{{all.views}}</td> 
     <td>{{all.datetime}}</td> 
    </tr> 
{% endfor %}   
</tbody> 
<tfoot> 
    <tr> 
     <td colspan="6">{{submit_button('DELETE')}}</td> 
    </tr> 
</tfoot> 
</table> 
{{end_form()}} 
+0

あなたのフォームは 'blog/delball'に送信されますが、あなたの削除コードはあなたの' deleteAction() ' – Timothy

+0

にあります。実際にはIDを取得できないし、複数のID配列を処理する方法はありますか? – munaz

+0

あなたのコントローラーコードは不明ですが、jqueryに構文ミスがあります。 '$( 'input [name = slId]')'は '$( 'input [name =" slId "]')'にする必要があります。名前の値が –

答えて

0

[コントローラ]

public function deleteBlogAction() 
{ 
    if($this->request->isPost() == true) 
    { 
     if($this->session->has('uname')) 
     { 
      $ids = $this->request->getPost('item');     
      foreach($ids as $item) 
      { 
       $blogs = Blogs::findFirst($item); 
#Erase Post Related Image      
       $uploadPath = 'uploads/blogs/'; 
       $defaultImg = $uploadPath.'empty.png'; 
       $getImg = $uploadPath.$blogs->bimage; 
       if($getImg == true AND $getImg != $defaultImg) 
       { 
        if(@unlink($getImg) == false) 
        { 
         echo('Uploaded Image Cannot Delete'); 
        } 
       } 
#Erase Post Related Comments  
       $deleteC = Comments::findByentry_id($item)->delete(); 
#Erase Blog Posts      
       $deleteB = Blogs::findFirst($item)->delete(); 
      } 
      if($deleteC != false AND $deleteB != false) 
      { 
       $this->flashSession->success("The post &amp; related comments has been deleted."); 
       return $this->response->redirect('blog/getBlog'); 
      } 
      else 
      { 
       $this->flashSession->error("Sorry! We are unable to delete."); 
       return $this->response->redirect('blog/getBlog'); 
      } 
     } 
     else 
     { 
      $this->flashSession->error("Unauthorised Access!"); 
      return $this->response->redirect('blog/getBlog');     
     } 
    } 
    else 
    { 
      $this->flashSession->error("Request May Not Posted."); 
      return $this->response->redirect('blog/getBlog');    
    } 
} 
0

私はちょうどこれと期待どおりに動作しているように見える!

[コントローラ]

public function deleteBlogAction() 
{ 
    if($this->request->isPost() == true) 
    { 
     if($this->session->has('uname')) 
     { 
      $ids = $this->request->getPost('item');     
      foreach($ids as $item) 
      { 
       $blogs = Blogs::findFirst($item); 
#Erase Post Related Image      
       $uploadPath = 'uploads/blogs/'; 
       $defaultImg = $uploadPath.'empty.png'; 
       $getImg = $uploadPath.$blogs->bimage; 
       if($getImg == true AND $getImg != $defaultImg) 
       { 
        if(@unlink($getImg) == false) 
        { 
         echo('Uploaded Image Cannot Delete'); 
        } 
       } 
#Erase Post Related Comments  
       $deleteC = Comments::findByentry_id($item)->delete(); 
#Erase Blog Posts      
       $deleteB = Blogs::findFirst($item)->delete(); 
      } 
      if($deleteC != false AND $deleteB != false) 
      { 
       $this->flashSession->success("The post &amp; related comments has been deleted."); 
       return $this->response->redirect('blog/getBlog'); 
      } 
      else 
      { 
       $this->flashSession->error("Sorry! We are unable to delete."); 
       return $this->response->redirect('blog/getBlog'); 
      } 
     } 
     else 
     { 
      $this->flashSession->error("Unauthorised Access!"); 
      return $this->response->redirect('blog/getBlog');     
     } 
    } 
    else 
    { 
      $this->flashSession->error("Request May Not Posted."); 
      return $this->response->redirect('blog/getBlog');    
    } 
} 

[ボルト]

{{ form('blog/deleteBlog', 'enctype': 'multipart/form-data') }} 
<table class="bloglist"> 
    <thead> 
     <tr class="fbold"> 
      <td>{{check_field('item','class':'toggle-button')}}</td> 
      <td>Title</td> 
      <td>Author</td> 
      <td>Views</td> 
      <td>PublishedOn</td> 
     </tr> 
    </thead> 
    <tbody> 
{%for all in ball %}  
     <tr class="zebra"> 
      <td>{{check_field('item[]','value':all.id)}}</td> 
      <td class="tal">{{all.btitle}}</td> 
      <td>{{all.bauthor}}</td> 
      <td>{{all.views}}</td> 
      <td>{{all.datetime}}</td> 
     </tr>  
{% endfor %}   
    </tbody> 
    <tfoot> 
     <tr> 
      <td colspan="6">{{submit_button('DELETE')}}</td> 
     </tr> 
    </tfoot> 
</table> 
{{end_form()}} 

[jqueryの]

$('.toggle-button').click(function(){ 
    $('input[type="checkbox"]').prop('checked', this.checked) 
}); 
1

あなたはdeclared methodとそれべき:

{{ form('blog/delete', 'method': 'post') }} 

データを受信するためにそれを使用しているあなたのよう:

$id = $this->request->getPost('id'); 

をあなたがポストを持つコントローラを要求しているかどうかをテストするには、コントローラでコードを拡張することができます。

if($this->request->isPost()) 
{ 
    // ... 
} else { 
    throw new \Exception('no_post'); 
} 
関連する問題