Concrete5 5.7: Using file objects in a single block controller

I am trying to attach a file object to a mail object.


I have included the following as my view:

$f = new Concrete\Core\Application\Service\FileManager();
//...
echo $f->file('file', 'test', 'pls choose');

Then I will send my form back to the controller. There (BTW, all other form fields are sent to the controller, as expected). I do:

$files = $this->post('test');
$file = \File::getByID($files);

which should return a File object. When i do

$file = \File::getRelativePathFromID($files);

it gives me the correct path to the selected file.

So far so good. BUT, when I try to send mail with the specified file:

$mail = Loader::helper('mail');
        $mail->setTesting(false);
        $mail->setSubject('test-subject');
        $mail->to($this->post('uEmail'));
//...
$attach = $mail->addAttachment($file);
        $attach->filename = 'tttt';
        $mail->sendMail();

the following error occurs:

call_user_func_array () expects parameter 1 to be a valid callback, class 'Concrete \ Core \ File \ Version' does not have a method 'getPath'

which apparently comes from this class method ( API ):

namespace Concrete\Core\Mail;
//...
class Service {
//...
    /**
      * Add attachment to send with an email.
      *
      * Sample Code:
      * $attachment = $mailHelper->addAttachment($fileObject);
      * $attachment->filename = "CustomFilename";
      * $mailHelper->send();
      *
      * @param File $fob File to attach
      * @return StdClass Pointer to the attachment
      */
     public function addAttachment(\Concrete\Core\File\File $fob)
     {
         // @TODO make this work with the File Storage Locations

         $fv = $fob->getVersion();
         $path = $fob->getPath();
         $name = $fv->getFileName();
         //...
      }
//...
}

, -, , - , , , , ? FileVersion, , , getPath().

:

$fv = $f->getApprovedVersion();
        $fv->setFile($f);
        $fv->getFile();

$fv = $f->getRecentVersion();
        $fv->setFile($f);
        $fv->getFile();

, , (??), / ?

+4
1

, ​​ , , , 7.4.

+3

All Articles