Jump to content

Updating repeater values


SIERRA
 Share

Recommended Posts

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

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

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

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

@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

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 by SIERRA
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...