cbc-design Posted November 3, 2021 Posted November 3, 2021 Hello together, i'm working on an admin page, listing all repeater items from different pages. Now i want to change the status of the repeater items from this admin page via API (1043 is the id of a specific repeater item): $this->pages->get("/test/")->test_repeater->find('1043')->addStatus(1); But "ProcessWire: ProcessSimple: Method RepeaterPageArray::addStatus does not exist or is not callable in this context" So i need help on how to set the status via API. Thank you, Christian.
kongondo Posted November 3, 2021 Posted November 3, 2021 Just a comment on the code (not the necessity or rationale of it): 20 minutes ago, cbc-design said: find('1043') A find in any context will always return a collection. In this case, a RepeaterPageArray. You cannot directly apply an action such as status to a whole collection. Although your code might have returned a result whose count is 1 (your 1043 item), it is still a collection. I.e., your 1043-item is in the collection RepeaterPageArray. So, your choices are: use get(1043), in order NOT to return a collection (e.g. RepeaterPage) or grab the first item in the collection, i.e. find(1043)->first(). Ideally, you should be checking that your get() returned something before apply an action to it. Otherwise, you might end up with a 'call to member function addStatus on null' error.
cbc-design Posted November 3, 2021 Author Posted November 3, 2021 @kongondo Thank you. Thas was one point. The other point was, that i saved the page, not the repeater itself. Now it works: $r = $this->pages->get("/test/")->test_repeater->find(1043)->first(); $r->setStatus(1); $r->save(); 1
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