Manaus Posted June 25, 2014 Posted June 25, 2014 Hello, I have some troubles on adding an uploaded file to a page, here is the code: <? $theReply = new Page(); $theReply->parent = $theparentPage; $theReply->template = $templates->get("mytemplate"); $theReply->of(false); $theReply->name = $sanitizer->name(first_n_words($input->post->reply, 5)); $theReply->save(); $theReply->of(true); if ($_FILES['attachment']['size'] > 0) { $upload_path = $config->paths->assets . "files/attachments/"; $doc_Upload = new WireUpload('attachment'); $doc_Upload->setMaxFiles(1); $doc_Upload->setOverwrite(false); $doc_Upload->setDestinationPath($upload_path); $doc_Upload->setValidExtensions($allowedExtensions); $doc_Uploaded = $doc_Upload->execute(); foreach ($doc_Uploaded as $du) { $pathname = $upload_path . $du; $theReply->documents->add($pathname); // <===== Call to a member function add() on a non-object unlink($pathname); } $theReply->save(); [...] } $theReply exists, $doc_Uploaded exists, still I get the error in the comment Any help would be greatly appreciated Thanks
adrian Posted June 25, 2014 Posted June 25, 2014 And the mytemplate template definitely contains a field called documents?
LostKobrakai Posted June 25, 2014 Posted June 25, 2014 I don't know if it has to do with that specific issue, but I think you should leave output-formatting off as long as you save stuff. 1
adrian Posted June 25, 2014 Posted June 25, 2014 Is the new page being created ok? I see that you are not defining a title for the page.
LostKobrakai Posted June 25, 2014 Posted June 25, 2014 What's getting display if you "var_dump($theReply);" just the line before the error? Maybe there's something overriding the variable?
Soma Posted June 25, 2014 Posted June 25, 2014 This error means add() isn't working with the "documents". The output formatting turned on, most likely the problem here. "documents" is single file field? 1
Manaus Posted June 26, 2014 Author Posted June 26, 2014 @Soma yes, of(true) was the problem Thanks everybody
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