gpt4 book ai didi

混凝土 5 5.7 : Using file objects in a Single Page Controller

转载 作者:行者123 更新时间:2023-12-01 02:10:21 24 4
gpt4 key购买 nike

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

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

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

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

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

我如何获得正确的文件对象,我必须(可能是 (??) )从该文件的最后/批准版本中取出?

最佳答案

This was a bug已经fixed in the upstream ,您必须自己修补或等到 7.4 版登陆。

关于混凝土 5 5.7 : Using file objects in a Single Page Controller,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29949776/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com