实体中未定义属性或方法



我有一个Usuario实体定义如下:

namespace CheckengineDashboardBundleEntity;
use DoctrineORMMapping as ORM;
use DoctrineCommonCollectionsArrayCollection;
use SymfonyComponentValidatorConstraints as Assert;
use SymfonyBridgeDoctrineValidatorConstraintsUniqueEntity;
use SymfonyComponentSecurityCoreUserUserInterface;
use SymfonyComponentHttpFoundationFileUploadedFile;
use JMSSerializerAnnotation as Serializer;
/**
 * Usuario.
 *
 * @ORMTable(name="usuarios")
 * @ORMEntity(repositoryClass="CheckengineDashboardBundleRepositoryUsuarioRepository")
 * @ORMHasLifecycleCallbacks()
 * @UniqueEntity("email")
 *
 * @SerializerExclusionPolicy("all")
 */
class Usuario implements UserInterface, Serializable
{
    ...
    /**
     * @var integer
     *
     * @todo No recibir ofertas del usuario.
     *
     * @ORMManyToMany(targetEntity="CheckengineDashboardBundleEntityEmpresa")
     * @ORMJoinTable(name="no_ofertas",
     *      joinColumns={@ORMJoinColumn(name="usuario_id", referencedColumnName="id")},
     *      inverseJoinColumns={@ORMJoinColumn(name="empresa_id", referencedColumnName="id")}
     * )
     *
     * @SerializerExpose
     * @SerializerType("ArrayCollection<CheckengineDashboardBundleEntityEmpresa>")
     * @SerializerMaxDepth(1)
     */
    private $noOfertas;
    ...
    public function __construct()
    {
        $this->noOfertas = new ArrayCollection();
    }
    ...
    /**
     * Add noOfertas.
     * @param CheckengineDashboardBundleEntityEmpresa $noOfertas
     * @return Usuario
     */
    public function addNoOfertas(Empresa $noOfertas)
    {
        $this->noOfertas[] = $noOfertas;
        return $this;
    }
    /**
     * Remove noOfertas.
     * @param CheckengineDashboardBundleEntityEmpresa $noOfertas
     */
    public function removeNoOfertas(Empresa $noOfertas)
    {
        $this->noOfertas->removeElement($noOfertas);
    }
    /**
     * Get noOfertas.
     * @return DoctrineCommonCollectionsCollection
     */
    public function getNoOfertas()
    {
        return $this->noOfertas;
    }
}

每当我尝试更新Usuario时,我都会收到以下错误:

既不是属性"noOfertas",也不是其中一个方法"addNoOferta()"/"removeNoOferta,类中存在"__set()"或"__call()"并具有公共访问权限"Checkengine\DashboardBundle\Entity\Usuario"。

这是updateAction()方法:

public function updateAction(Request $request, $id)
{
    $em = $this->getDoctrine()->getManager();
    $entity = $em->getRepository('DashboardBundle:Usuario')->find($id);
    if (!$entity) {
        throw $this->createNotFoundException('Unable to find Usuario entity.');
    }
    $deleteForm = $this->createDeleteForm($id);
    $editForm = $this->createEditForm($entity);
    $current_pass = $entity->getPassword();
    $editForm->handleRequest($request);
    if ($editForm->isValid()) {
        if (null == $entity->getPassword()) {
            $entity->setPassword($current_pass);
        } else {
            $this->setSecurePassword($entity);
        }
        $em->flush();
        return $this->redirect($this->generateUrl('usuarios_edit', array('id' => $id)));
    }
    return array(
        'entity'      => $entity,
        'form'        => $editForm->createView(),
        'delete_form' => $deleteForm->createView(),
    );
}

那里可能出了什么问题?我缺少什么?我已经清理了好几次缓存,还重新启动了Web服务器(以防万一),但仍然没有任何问题,这让我抓狂,有什么建议吗?线索

如错误消息所示,您需要添加/删除一个$noOferta对象,而不是整个集合$noOfertas

你需要重写这样的方法:

public function addNoOferta(Empresa $noOferta)
{
    $this->noOfertas[] = $noOferta;
    return $this;
}
public function removeNoOferta(Empresa $noOferta)
{
    $this->noOfertas->removeElement($noOferta);
}

相关内容

  • 没有找到相关文章

最新更新