表单提交时出现 Symfony 错误 ....“必须是给定字符串的 varchar 实例”

发布于 2024-12-05 08:15:23 字数 930 浏览 5 评论 0原文

运行 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

岁吢 2024-12-12 08:15:23

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)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文