Delete multiple selected rows in phalcon

munaz

I want to delete selected multiple rows or all rows on a single click. But i cant figure it. how could i do this with my code? please edit my code for expected result.

Here is my jquery for select all rows

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

How to get id's in to controller to execute delete process? My jquery does not sends any id, i tested with var_dump its shows 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()}}  
munaz

[Controller]

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');            
    }
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

jqgrid - Delete multiple selected rows

From Dev

Trying to delete selected row from datagridview but it is deleting multiple rows

From Dev

how to add multiple selected options in phalcon

From Dev

Delete selected rows in mysql

From Dev

Delete selected rows in uitable

From Dev

how to delete selected rows (multiple rows) from CheckboxTableViewer when button clicks? (table is connected to oracle database)

From Dev

How to delete selected rows in uitable?

From Dev

How to delete selected rows in uitable?

From Dev

Delete multiple rows in JavaScript

From Dev

Delete multiple rows in a ListVIew

From Dev

Hide multiple selected rows with jquery

From Dev

MySQL Delete all selected rows in one request

From Dev

MySQL query to Select -> Insert and Delete selected rows

From Dev

Continuous Form, Delete button for selected Rows

From Dev

How to delete selected rows from a DataGridView?

From Dev

MySQL query to Select -> Insert and Delete selected rows

From Dev

How to delete the rows corresponding to the selected `yes` input?

From Dev

Delete multiple rows in SQLITE (android)

From Dev

Delete multiple rows using IDs?

From Dev

JTable delete multiple rows with AbstractTableModel

From Dev

MySQL delete multiple rows if they exist

From Dev

How to delete multiple rows with JdbcTemplate

From Dev

Delete multiple rows in SQLITE (android)

From Dev

Delete multiple rows using IDs?

From Dev

Delete multiple rows using Jquery

From Dev

MySQL delete multiple rows in multiple tables

From Dev

Postgresql delete multiple rows from multiple tables

From Dev

Delete multiple rows in Codeigniter by multiple columns

From Dev

How to get multiple selected rows in a table or indexedcontainer?

Related Related

HotTag

Archive