Jump to content

Recommended Posts

Posted

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

Posted

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

Posted

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');
}

Posted

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

 

Posted

@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.

Posted (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 by SIERRA
Posted

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.

  • Like 1

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
  • Recently Browsing   0 members

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