Jump to content

Adding / Removing items to a Multiple Pages PageArray through code


Inxentas
 Share

Recommended Posts

I add some pages to a PageReferences field that I've set to Multiple Pages PageArray. I add stuff to it like this, which works fine.

$user->of(false);
$newfav = $pages->find($id);
$user->favs->add($newfav);
$user->save();

I'm trying to remove some items from it, but this doesn't seem to do anything. Here's the code:

if($user->isLoggedin())
    {
        $found = false;
        foreach($user->favs as $fav){
            if($fav->id === $id){
                $found = true;
            }
        }
        if($found){
            $user->of(false);
            $newfav = $pages->find($id);
            $user->favs->remove($newfav);
            $user->save();
        } 
    }

I already fixed an error where the $id variable wasn't an integer, I'm sure that I end up finding $newfav and that the save() method is called.

 

 

Edited by Inxentas
Link to comment
Share on other sites

  • Inxentas changed the title to Adding / Removing items to a Multiple Pages PageArray through code

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