Jump to content

Deleting items in AsmSelect


celfred
 Share

Recommended Posts

Hello,

I'm coming back to you since I've finally managed to extract the 'buggy' part of my code. Here's my problem :

When a player loses a level, I want this player to lose all his equipment, so I wrote :

foreach ($player->equipment as $equipment) {
  $equipment->delete();
}

But here's what happens : The original equipment pages get deleted ! Not just the item in the AsmSelect !

And I just can't figure why this happens ! Yet I'm sure I am misunderstanding some basic principle here... So if anyone could give me a hint, I'd appreciate.

To be more precise : my equipment list is in my tree in equipment/weapons/ and has many pages, such as sword, bow, gun... (It looks violent but it's not, it's a classroom experiment to motivate teenagers :) ) and my AsmSelect resides in a player template so whenever a player has the possibility, he can select an equipment page. Everything works fine, except when I use this 'delete' line :(

In other words, how could I clean this asmSelect without actually deleting the pages in the original equipment tree?

Thanks in advance !

  • Like 1
Link to comment
Share on other sites

$player->of(false);
foreach($player->equipment as $equipment){
    $u->equipment->remove($equipment);
}
$u->save("equipment");

EDIT: Ignore this and go with BitPoet's solution. I was just confirming that removeAll() worked, but he beat me to it :)

  • Like 3
Link to comment
Share on other sites

Thank you so much ! I can't believe I've passed through this one... It caused me a real headache having to manually repair the bad work with my 'delete' function.

Now I've learned something again tonight thanks to both of you and I'm still enjoying more and more discovering ProcessWire :)

Thanks again !

  • Like 2
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...