35 Posts
julien
6 years ago
6
Topic

Hello All,

I've a list of content in frontend. I use the jgrid plugin with ckeckbox view, so i can select some content.

For the moment i can only delete  one content with a field "Icon_trash" who have  the link 'delete' in typography plugin (button 2)

I want delete item who are selected with the checkbox from my list.

So is there a easely way to delete more than one content (selected item)?

Cordially,

Julien

Get a Book for SEBLOD
4229 Posts
Kadministrator
6 years ago
5
Level 1

Currently only reordering is supported out of the box, for delete you would need to add some javascript to add ids of checked rows to store ids in variable and post this variable to delete function when button is clicked.

35 Posts
julien
6 years ago
4
Level 2

Hello Klas,

So i only use jgrid plugin to display checkbox on the cck_id field and a submit button in my search view of my list.

First i try this code in my search override php file and i can have each cck_id who have been selected :

if (isset($_GET['cid'])){
    foreach ($_GET['cid'] as $key=>$value)
    {
       //echo $value.','; It's work!
       delete($value);// function unknow, error php!!
    }
}

But what's the name of the function to delete a content??

/***********************************************************************************/

I try an other way. I've look at the link on a delete icon in my list view and i try this:

if (isset($_GET['cid'])){
    foreach ($_GET['cid'] as $key=>$value)
    {

        file_get_contents(JURI::Base()."index.php/les-structures?task=delete&cid=".$value);
    }
}

But the content is not delete... When i copy and paste this link in my browser the content is delete.

Maybe i need curl...

What is the best way to delete a list of content??

Cordially

Julien

4229 Posts
Kadministrator
6 years ago
3
Level 3

Hi, file_get_contents won't work for this as far as I know, you need to use curl (and cid variable needs to be set as array). But you can do it differently, there is JCckContent->delete function that can be used directly in your code.

35 Posts
julien
6 years ago
2
Level 4

Thanks Klas.

 I can now delete my checked item with JCckContent->delete. It's work.

I used this tutorial to help me.

I share my code:

if (isset($_GET['cid'])){
    foreach ($_GET['cid'] as $key=>$content_id)
    {
    $content_to_delete = new JCckContent(array('joomla_article') )
    $content_to_delete->load($content_id);
    $content_to_delete->delete();
    }
    $url="Refresh:0;url=".JURI::Base()."index.php/les-structures"; 
    header($url);  // Refresh url to load the result and clean the url

}

Before today, I never load a content by code. Is it correct? There are no way to load directly a content?

4229 Posts
Kadministrator
6 years ago
0
Level 5

Hi,

your code seems correct.

151 Posts
jimenaes
3 years ago
0
Level 5

Hello

I cannot find information to understand how I can modify the value of a field in several contents at the same time from a list. This post is the closest thing but it is not clear to me how to link the selected records (with the checkbox JGrid typo) with a button and with the code (before store, after store?, I do not know which one I should use for this case). Could anybody help me with this?

Thanks

Get a VIP membership