Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/257.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 可捕获的致命错误:无法将类代理\\uuuu CG\uuuuu\AppBundle\Entity\Ticket的对象转换为字符串_Php_Symfony_Relationship - Fatal编程技术网

Php 可捕获的致命错误:无法将类代理\\uuuu CG\uuuuu\AppBundle\Entity\Ticket的对象转换为字符串

Php 可捕获的致命错误:无法将类代理\\uuuu CG\uuuuu\AppBundle\Entity\Ticket的对象转换为字符串,php,symfony,relationship,Php,Symfony,Relationship,我在使用Symfony2的项目中遇到问题。是一个“worklog”项目,具有特定项目的票证(问题)。但当我尝试编辑worklog条目时,出现以下错误: 可捕获的致命错误:类的对象 代理\uuuu CG\uuuuu\AppBundle\Entity\Ticket无法转换为 串 这是我的数据库模型: 这是AppBundle/Entity/Worklog代码的一部分/ /** * @var \Ticket * * @ORM\ManyToOne(targetEntity="Ticket") *

我在使用Symfony2的项目中遇到问题。是一个“worklog”项目,具有特定项目的票证(问题)。但当我尝试编辑worklog条目时,出现以下错误:

可捕获的致命错误:类的对象 代理\uuuu CG\uuuuu\AppBundle\Entity\Ticket无法转换为 串

这是我的数据库模型:

这是AppBundle/Entity/Worklog代码的一部分/

/**
 * @var \Ticket
 *
 * @ORM\ManyToOne(targetEntity="Ticket")
 * @ORM\JoinColumns({
 *   @ORM\JoinColumn(name="ticket_ticket_id", referencedColumnName="ticket_id")
 * })
 */
private $ticketTicket;
和来自AppBundle/实体/票据/

/**
 * @var integer
 *
 * @ORM\Column(name="ticket_id", type="integer", nullable=false)
 * @ORM\Id
 * @ORM\GeneratedValue(strategy="IDENTITY")
 */
private $ticketId;
你知道我为什么会有这样的错误吗?有什么可以帮忙的吗

工作日志表格:

/**
 * @param FormBuilderInterface $builder
 * @param array $options
 */
public function buildForm(FormBuilderInterface $builder, array $options)
{
    $builder
        ->add('worklogDate')
        ->add('worklogDuration')
        ->add('worklogDescription')
        ->add('ticketTicket')
    ;
}

/**
 * @param OptionsResolverInterface $resolver
 */
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
    $resolver->setDefaults(array(
        'data_class' => 'AppBundle\Entity\Worklog'
    ));
}

/**
 * @return string
 */
public function getName()
{
    return 'appbundle_worklog';
}

问题是您的实体字段没有预期的返回。 尝试添加:


为什么不在
表单
类中完全声明字段呢。它将是这样的smth:

->add('ticketTicket', 'entity', array(
    'class' => 'AppBundle\Entity\Ticket',
    'property' => 'propertyName', //needed property's name
    'label' => 'choice_field_label'
))
如果您需要更复杂的smth,则只需为该字段查找DALL,您可以使用查询生成器选项:

->add('ticketTicket', 'entity', array(
    'class' => 'AppBundle\Entity\Ticket',
    'property' => 'propertyName', //needed property's name
    'label' => 'choice_field_label',
    'query_builder' => function(EntityRepository $er) {
        return $er->findAllTicketNames(); 
        //Where findAllTicketNames is the name of method in your
        // ticketRepo which returns queryBuilder, 
        //instead of this you could just write your custom query like
        //$qb = $er->createQueryBuilder('t');
        //$qb->andWhere(...);
        //return $qb;
    } 
))
p、 s.

我的答案是从我以前的答案复制过来的,并添加了一些小的修改以适应您的情况:)

您是否也有用于编辑worklog条目的表单的代码?是否清除了缓存<代码>php应用程序/控制台缓存:clear-e dev我从表单中添加了代码。清除缓存不工作。将public _toString()方法添加到票证实体类,并返回票证名称。谢谢helios!他在工作!
->add('ticketTicket', 'entity', array(
    'class' => 'AppBundle\Entity\Ticket',
    'property' => 'propertyName', //needed property's name
    'label' => 'choice_field_label',
    'query_builder' => function(EntityRepository $er) {
        return $er->findAllTicketNames(); 
        //Where findAllTicketNames is the name of method in your
        // ticketRepo which returns queryBuilder, 
        //instead of this you could just write your custom query like
        //$qb = $er->createQueryBuilder('t');
        //$qb->andWhere(...);
        //return $qb;
    } 
))