您好,
我有一个假模型(没有任何与之关联的表的实体),用于验证联系表单。我想从另一张桌子上取一封电子邮件。我创建了一个DataTranformer,并将其与我的模型的电子邮件字段绑定。
现在,当我尝试提交表单时,它给了我这个错误:
An exception occurred while executing 'SELECT t0.firstName AS firstName1, t0.lastName AS lastName2, t0.email AS email3, FROM Contact t0 WHERE t0.email = ? LIMIT 1' with params [{}]:\n\nObject of class App\\ApiBundle\\Model\\EmailCo could not be converted to string"
如何解决这个问题。
这是我的模型类:
namespace App\ApiBundle\Model;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Validator\ExecutionContext;
use Doctrine\ORM\Mapping as ORM;
class EmailCo
{
/**
* @var string Email Id
* @Assert\NotBlank()
* @Assert\Email()
*/
protected $email;
/**
* @var string Mail Subject
* @Assert\NotBlank()
* @Assert\Length(
* min = 3,
* max = 200,
* minMessage = "Subject must be at least {{ limit }} characters long",
* maxMessage = "Subject cannot be longer than {{ limit }} characters long"
* )
*/
protected $subject;
/**
* @var string The note message
* @Assert\NotBlank()
* @Assert\Length(
* min = 3,
* max = 200,
* minMessage = "Subject must be at least {{ limit }} characters long",
* maxMessage = "Subject cannot be longer than {{ limit }} characters long"
* )
*/
protected $message;
/**
* @var bool Send a copy to user or not
* @Assert\NotBlank()
*/
protected $sendCopyToMe;
public function setEmail($email)
{
$this->email = $email;
}
public function getEmail()
{
return $this->email;
}
public function setSubject($subject)
{
$this->subject = $subject;
}
public function getSubject()
{
return $this->subject;
}
public function setMessage($message)
{
$this->message = $message;
}
public function getMessage()
{
return $this->message;
}
public function setSendCopyToMe($sendCopyToMe)
{
$this->sendCopyToMe = $sendCopyToMe;
}
public function getSendCopyToMe()
{
return $this->sendCopyToMe;
}
}
答案 0 :(得分:0)
错误消息显示对象无法转换为字符串。这通常通过函数__toString
完成,您可以将其添加到EmailCo
类:
public function __toString()
{
return '...';
}
了解更多信息have a look here