Jump to content

Set status of repeater item from api


cbc-design
 Share

Recommended Posts

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.

Link to comment
Share on other sites

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.

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...