Jump to content

Adding a file to Pagefiles and saving to Database


ethanbeyer
 Share

Recommended Posts

I'm kind of at a loss with this: I wrote a function inside one of my modules that saves files to a Page through the API. The Field is a FieldtypeFile.

$page = $this->storagePage;

$files = $page->pdfStorage_files;
$files->add($path);

return $page->save($files);

I can see that the file has been saved to the Page's directory, and if I dump $page->filesManager->getFiles(); , the file I add is present in the array.

But in the field_pdfstorage_files table in the database - no entry. Which also means that the file is not visible as a part of the pdfStorage_files field in the Admin Backend.

 

Is there a way to ensure that adding the file to the field saves it everywhere?

Link to comment
Share on other sites

Does this work?

$p = $this->storagePage;
$p->of(false);
$p->pdfStorage_files->add($path);
$p->save('pdfStorage_files');
return $p->pdfStorage_files;

Not sure if your problem is the missing $p->of(false) or trying to save the $files pagefile object instead of the "pdfStorage_files" field name.

PS - what @Robin S said :)

  • Like 2
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...