Manaus Posted March 10, 2014 Share Posted March 10, 2014 Hello, I need to delete a cropimage field content [a single item field], tried $page->image->remove(), $page->image->delete(), $page->image->deleteAll() but they do not work. Thanks for any suggestion... Link to comment Share on other sites More sharing options...
ryan Posted March 16, 2014 Share Posted March 16, 2014 Is $page->image a single image (max files = 1?). If so, access $page->image is an object of type Pageimage, which has no remove() or delete() or deleteAll() methods. Those are instead methods of the WireArray that contains the file(s)/image(s). You could access that a couple of different ways. One way would be to get the "unformatted" value, which for files, always returns the containing WireArray: $page->getUnformatted('image')->delete($page->image); Another way would be to access the 'pagefiles' property of the image, which also refers to the containing WireArray. $page->image->pagefiles->delete($page->image); I mention the above examples for explanation, but PLEASE IGNORE THE ABOVE. Any time you are performing manipulations to a page, you should have the page's output formatting turned OFF. So there really isn't any situation in which you would use the above API examples... because it would mean you are modifying a page that is in an output-ready state, rather than a change-ready state. That's why ProcessWire throws an exception if you try to save a page with output formatting state active. The second point I want to make is that simply calling a delete() is queuing a deletion, not executing it. You still need to $page->save() or $page->save('image') before the deletion is committed. Given all this, I think this is what you want: $page->of(false); // turn off output formatting $page->image->delete($page->image); // you can use this line... $page->image->deleteAll(); // ...or this line (choose one) $page->save('image'); // or use $page->save(); if also saving other changes 3 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now