表单提交时出现 Symfony 错误 ....“必须是给定字符串的 varchar 实例”
运行 Symfony2
提交表单后,出现以下错误:
Catchable Fatal Error: Argument 1 passed to Depot\StarterBundle\Entity\Application::setPropAddr() must be an instance of varchar, string given, called in C:\wamp\www\Symfony\vendor\symfony\src\Symfony\Component\Form\Util\PropertyPath.php on line 346 and defined in C:\wamp\www\Symfony\src\Depot\StarterBundle\Entity\Application.php line 211
这是有问题的块:
/**
* Set prop_addr
*
* @param varchar $propAddr
*/
public function setPropAddr(\varchar $propAddr)
{
$this->prop_addr = $propAddr;
}
/**
* Get prop_addr
*
* @return varchar
*/
public function getPropAddr()
{
return $this->prop_addr;
}
如果我在 setPropAddr() 函数中从“\varchar $propAddr”中删除 /varchar,它就会起作用。但这个实体是从命令行创建的,所以这里肯定有一个更大的问题。
这是我的 Application.orm.yml 中的行
prop_addr:
type: string(255)
有什么问题吗?
Running Symfony2
Upon submitting a form, here is the error I get:
Catchable Fatal Error: Argument 1 passed to Depot\StarterBundle\Entity\Application::setPropAddr() must be an instance of varchar, string given, called in C:\wamp\www\Symfony\vendor\symfony\src\Symfony\Component\Form\Util\PropertyPath.php on line 346 and defined in C:\wamp\www\Symfony\src\Depot\StarterBundle\Entity\Application.php line 211
Here is the block in question:
/**
* Set prop_addr
*
* @param varchar $propAddr
*/
public function setPropAddr(\varchar $propAddr)
{
$this->prop_addr = $propAddr;
}
/**
* Get prop_addr
*
* @return varchar
*/
public function getPropAddr()
{
return $this->prop_addr;
}
If I remove the /varchar from "\varchar $propAddr" in the setPropAddr() function, it works. But this entity was created from the command line so there must be a bigger issue here.
And here is the line in my Application.orm.yml
prop_addr:
type: string(255)
What is the issue?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
public function setPropAddr(\varchar $propAddr)
这显然是错误的,似乎它已经采用了 DB 类型并将其添加为 Class TypeHint。一般来说,您不应该使用 Doctrine2 自动生成任何内容(将阻止您覆盖内容并修复错误生成的设置器)public function setPropAddr(\varchar $propAddr)
This is clearly wrong, seems like it have taken the DB type and added that as a Class TypeHint. Generally you shouldn't autogenerate anything with Doctrine2 (Will keep you from overwriting stuff and fixing wrongly generated setters)