Manaus Posted June 25, 2014 Share 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 Link to comment Share on other sites More sharing options...
adrian Posted June 25, 2014 Share Posted June 25, 2014 And the mytemplate template definitely contains a field called documents? Link to comment Share on other sites More sharing options...
LostKobrakai Posted June 25, 2014 Share 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 Link to comment Share on other sites More sharing options...
Manaus Posted June 25, 2014 Author Share Posted June 25, 2014 @adrian yes it does Link to comment Share on other sites More sharing options...
adrian Posted June 25, 2014 Share Posted June 25, 2014 Is the new page being created ok? I see that you are not defining a title for the page. Link to comment Share on other sites More sharing options...
LostKobrakai Posted June 25, 2014 Share 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? Link to comment Share on other sites More sharing options...
Soma Posted June 25, 2014 Share 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 Link to comment Share on other sites More sharing options...
Manaus Posted June 26, 2014 Author Share Posted June 26, 2014 @Soma yes, of(true) was the problem Thanks everybody Link to comment Share on other sites More sharing options...
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