Tobias Posted February 26, 2021 Posted February 26, 2021 Hello community, I'm using https://processwire.com/modules/rest-api/ to define some REST API endpoints for my ProcessWire. One of these endpoints receives an ID in the path via /api/foo/:id . I search for the page using $pages->get() and can confirm that it's found. The tricky part is now that when I do $my_page->trash() or $pages->trash($my_page) I end up with the following error: "Attempt to read property "id" on null. File: [...]\wire\core\PagesEditor.php:296" Which seems to be the case because ProcessWire checks with $this->wire("page")->id if the current page is the one I try to trash/delete. Understandably there is no current page when this is not a template file. So how could one proceed to trash/delete a page via REST API if the aforementioned ProcessWire APIs won't work? Best regards Tobias
bernhard Posted February 28, 2021 Posted February 28, 2021 Hi Tobias, welcome to the forum! Sorry, I have no answer for you, but I can just tell you that I've never had any problems using $page->trash() in any of my projects. So your tricky part should really not be tricky at all ? Maybe there's something else going on... 1 1
dotnetic Posted March 1, 2021 Posted March 1, 2021 Please provide the code that you use. The error says, that it is trying to read the property of a null object. That means, that $my_page is not a page and therefore ProcessWire can't get the id of this page. If you have an id for the page do `$pages->get(insertIdHere)->trash();`
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