SIERRA Posted May 3, 2018 Share Posted May 3, 2018 Hi I am using a repeater field as below booked_days date_value time_from bookings_done I would like to increase the bookings_done by one against a date and time. So I used below code. But it shows error as 'Error: Exception: Can’t save page ...' $datetofind=strtotime("2018-05-11"); $timefromfind="10:00 pm"; $bookeddetails = $page->booked_days->find("date_value={$datetofind}, time_from={$timefromfind} "); foreach ($bookeddetails as $bookeddetail) { $bookeddetail->bookings_done++; $bookeddetail->save(); } Could you please suggest on this. Thanks Link to comment Share on other sites More sharing options...
psy Posted May 3, 2018 Share Posted May 3, 2018 Couple of things to try: 1. Maybe turn formatting off, ie $bookdetail->of(false); 2. Maybe just saving the field will do, ie: // $bookdetail->save(); $bookdetail->setAndSave('bookings_done'); Untested... Link to comment Share on other sites More sharing options...
SIERRA Posted May 3, 2018 Author Share Posted May 3, 2018 Thanks I tried but this shows error as 'Error: Call to a member function of() on null ' Now the code is foreach ($bookeddetails as $bookeddetail) { $bookeddetail->bookings_done=10; $bookdetail->of(false); $bookdetail->setAndSave('bookings_done'); } Link to comment Share on other sites More sharing options...
SIERRA Posted May 3, 2018 Author Share Posted May 3, 2018 Hi I also tried to remove an repeater item. This is also not working. Please suggest is there any permission issue. If I run the below code Id value is getting displayed but not able to delete $page = $pages->get(1128); $datetofind=strtotime("2018-05-11"); $timefromfind="10:00 pm"; $bookeddetails = $page->booked_days->find("date_value={$datetofind}, time_from={$timefromfind} "); echo "Id ".$bookeddetails."<br/>"; $page->booked_days->remove($bookeddetails); $page->save(); Thanks Link to comment Share on other sites More sharing options...
bernhard Posted May 3, 2018 Share Posted May 3, 2018 @psy used $bookdetail, whereas @SIERRA you used $bookeddetail Use TracyDebugger and you'll easily be able to solve such issues on your own via the bd() function (bar dump), eg bd($bookdetail) would have showed you that this is not a repeateritem but NULL Also it might be helpful to post the whole error message for us... And please use the code option for pasting code in the forum. Link to comment Share on other sites More sharing options...
SIERRA Posted May 4, 2018 Author Share Posted May 4, 2018 (edited) Hi Thanks, below code is working fine. The issue is due to incorrect name foreach ($bookeddetails as $bookeddetail) { $bookeddetail->bookings_done=10; $bookeddetail->of(false); $bookeddetail->setAndSave('bookings_done');} Edited May 4, 2018 by SIERRA Link to comment Share on other sites More sharing options...
bernhard Posted May 4, 2018 Share Posted May 4, 2018 If you use setandsave there is no need for the upper two lines. Only this in the foreach: ...setAndSave('bookings_done', 10); Is the best way to do it. 1 Link to comment Share on other sites More sharing options...
SIERRA Posted May 4, 2018 Author Share Posted May 4, 2018 Hi, Noted, thanks 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