Concrete5 5.7:在单页控制器中使用文件对象

Concrete5 5.7: Using file objects in a Single Page Controller

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


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

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

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

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

其中应该 return 一个文件对象。当我这样做时

$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() expects parameter 1 to be a valid callback, class 'Concrete\Core\File\Version' does not have a method 'getPath'

这显然来自这个 class 方法 (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();

我如何获得正确的文件对象,我必须从这个文件的 last/approved 版本中取出,也许 (??)?

This was a bug that has been fixed in the upstream,您必须自行修补或等待 7.4 版发布。