4

我尝试将文件对象附加到邮件对象。


我在我的观点中包含了以下内容:

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

然后我将表单提交回控制器。那里(顺便说一句,所有其他表单字段都按预期到达控制器)我这样做:

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

应该返回一个 File 对象。当我做

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

它为我提供了所选文件的正确路径。

到目前为止,一切都很好。但是当我尝试发送附有该文件对象的邮件时:

$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();

出现以下错误:

call_user_func_array() 期望参数 1 是一个有效的回调,类 'Concrete\Core\File\Version' 没有方法 'getPath'

这显然来自此类方法(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 回答 1

3

这是一个在上游修复的错误,您必须自己修补此问题或等到版本 7.4 登陆。

于 2015-04-29T17:56:56.063 回答