【问题标题】:Expected argument of type "AppBundle\Entity\Sales", "DateTime" given给定“AppBundle\Entity\Sales”、“DateTime”类型的预期参数
【发布时间】:2017-12-08 21:33:59
【问题描述】:

无论使用何种日期格式(Symfony 3.3.14),提交具有以下字段定义的表单时都会出现标题错误:

use Symfony\Component\Form\Extension\Core\Type\DateType;
...

    $builder
        ->add('sales', DateType::class, [
            'widget' => 'single_text',
            'html5' => false,
            'attr' => ['class' => 'js-datepicker'],
            'format' => 'mm-dd-yyyy',
            ])

以及相关的 javascript

$('.js-datepicker').datepicker({
    format: 'mm-dd-yyyy'
});

在模板中调用

{{ form_row(form.sales) }}
...
    {%  block javascripts %}
        {{ parent() }}
        <script src="/js/bootstrap-datepicker.js"></script>
        <script src="/js/tickets.js"></script>
    {%  endblock javascripts %}

【问题讨论】:

  • 您的实体中的$sales 是否定义为您的实体本身与AppBundle\Entity\Sales 实体之间的关系?
  • 当我意识到这一点时,您的评论就来了。将其发布为答案,我会接受并删除我的。
  • 好吧,你可以接受你的:)
  • 你太客气了。你确定不会?我不介意。
  • 当然,没问题,但感谢您的提问。

标签: php symfony symfony-forms


【解决方案1】:

DOH!

如何获得包含销售字段的实体定义

public function setSales(Sales $sales)
{
    $this->sales = $sales;

    return $this;
}

应该是什么时候

public function setSales($sales)
{
    $this->sales = $sales;

    return $this;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-30
    • 1970-01-01
    • 1970-01-01
    • 2017-04-11
    相关资源
    最近更新 更多