Guy Verville Posted August 5, 2018 Share Posted August 5, 2018 Hi, I'm trying to simply save an image contained in a Repeater Matrix field. But I get an error with this code: $added = $p->member_mx_images->getNew(); $added->member_images->add($responseAdded['imageURL']); $added->crm_products_sold = $products; $added->save(); $p->of(false); $p->member_mx_images->add($added); $p->save(); The error is: Call to a member function add() on null at the line $added->member_images->add($responseAdded['imageURL']); member_images is the image field. If I remove the add instruction, nothing is saved. $responseAdded['imageURL'] is a valid address coming from and external site (my purpose is to make two Processwire sites communicate certain information). crm_products_sold is a Page reference field. $products is an array of IDs. If I remove the instruction for member_images, I do get a repeater saved, but it is empty anyway. I don't know what I am doing wrong. Link to comment Share on other sites More sharing options...
Robin S Posted August 5, 2018 Share Posted August 5, 2018 You have to save a newly created page (including a repeater page) before you can add files or images to it. $added = $p->member_mx_images->getNew(); $added->save(); $added->member_images->add($responseAdded['imageURL']); $added->crm_products_sold = $products; $added->save(); $p->of(false); $p->member_mx_images->add($added); $p->save(); 2 Link to comment Share on other sites More sharing options...
Guy Verville Posted August 6, 2018 Author Share Posted August 6, 2018 Thank you for answering. I did that before, but it's not working. Still the same error. Given: Site accepting the request: mq.local Site where the file resides: afmq.local $responseAdded['imageURL] = http://afmq.local/site/assets/files/1862/img_0729.jpg Since the url given is outside mq.local, should I download the file before? Link to comment Share on other sites More sharing options...
Soma Posted August 6, 2018 Share Posted August 6, 2018 You need to set the type of the repeater matrix.... ie: $new->repeater_matrix_type = 1; and save the item before adding files. And you don't need to add the new item to the field after that, it's already added. 3 1 Link to comment Share on other sites More sharing options...
Guy Verville Posted August 6, 2018 Author Share Posted August 6, 2018 Thanks a lot, it works. 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