Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/291.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 Symfony3-“;“无法识别的字段”;基于多对一关系属性的值提取条目时出现异常_Php_Doctrine Orm_Doctrine_Symfony - Fatal编程技术网

Php Symfony3-“;“无法识别的字段”;基于多对一关系属性的值提取条目时出现异常

Php Symfony3-“;“无法识别的字段”;基于多对一关系属性的值提取条目时出现异常,php,doctrine-orm,doctrine,symfony,Php,Doctrine Orm,Doctrine,Symfony,我希望显示实体中的记录,但仅显示loginID值等于当前用户ID的记录。在事件实体中,loginID是多对一属性。 我有以下事件: namespace Vendor\MyBundle\Entity; use Doctrine\ORM\Mapping as ORM; use Symfony\Component\HttpFoundation\File\UploadedFile; use Symfony\Component\Validator\Constraints as Assert; /**


我希望显示实体中的记录,但仅显示loginID值等于当前用户ID的记录。在事件实体中,loginID是多对一属性。

我有以下事件:
namespace Vendor\MyBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\Validator\Constraints as Assert;

/**
 * Events
 *
 * @ORM\Table(name="events")
 * @ORM\Entity
 */
class Events
{
    /**
     * @var string
     *
     * @ORM\Column(name="EventName", type="string", length=255, nullable=false)
     */
    private $eventname;

    /**
     * @var string
     *
     * @ORM\Column(name="Location", type="string", length=255, nullable=false)
     */
    private $location;

    /**
     * @var \DateTime
     *
     * @ORM\Column(name="StartDate", type="datetime", nullable=false)
     */
    private $startdate;

    /**
     * @var \DateTime
     *
     * @ORM\Column(name="EndDate", type="datetime", nullable=false)
     */
    private $enddate;

    /**
     * @var boolean
     *
     * @ORM\Column(name="Status", type="boolean", nullable=false)
     */
    private $status;

    /**
     * @var integer
     *
     * @ORM\Column(name="eventID", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="IDENTITY")
     */
    private $eventid;



    /**
     * Set eventname
     *
     * @param string $eventname
     *
     * @return Events
     */
    public function setEventname($eventname)
    {
        $this->eventname = $eventname;

        return $this;
    }

    /**
     * Get eventname
     *
     * @return string
     */
    public function getEventname()
    {
        return $this->eventname;
    }

    /**
     * Set location
     *
     * @param string $location
     *
     * @return Events
     */
    public function setLocation($location)
    {
        $this->location = $location;

        return $this;
    }

    /**
     * Get location
     *
     * @return string
     */
    public function getLocation()
    {
        return $this->location;
    }

    /**
     * Set startdate
     *
     * @param \DateTime $startdate
     *
     * @return Events
     */
    public function setStartdate($startdate)
    {
        $this->startdate = $startdate;

        return $this;
    }

    /**
     * Get startdate
     *
     * @return \DateTime
     */
    public function getStartdate()
    {
        return $this->startdate;
    }

    /**
     * Set enddate
     *
     * @param \DateTime $enddate
     *
     * @return Events
     */
    public function setEnddate($enddate)
    {
        $this->enddate = $enddate;

        return $this;
    }

    /**
     * Get enddate
     *
     * @return \DateTime
     */
    public function getEnddate()
    {
        return $this->enddate;
    }

    /**
     * Set status
     *
     * @param boolean $status
     *
     * @return Events
     */
    public function setStatus($status)
    {
        $this->status = $status;

        return $this;
    }

    /**
     * Get status
     *
     * @return boolean
     */
    public function getStatus()
    {
        return $this->status=true;
    }

    /**
     * Get eventid
     *
     * @return integer
     */
    public function getEventid()
    {
        return $this->eventid;
    }

    /**
     * Get web path to upload directory.
     * 
     * @return string
     * Relative path.
     */
    protected function getUploadPath()
    {
        return 'uploads/eventCovers';
    }

    /**
     * Get absolute Path.
     * 
     * @return string
     * Absolute path.
     */
    protected function getUploadAbsolutePath()
    {
        return __DIR__ . '/../../../../web/' . $this->getUploadPath();
    }

    /**
     * Get web path to a cover.
     * 
     * @return null|string
     * Relative path.
     */
    public function getCoverWeb()
    {
        return NULL === $this->getCover()
                ? NULL
                : $this->getUploadPath() . '/' . $this->getCover();
    }

    /**
     * Get web path on disk to a cover.
     * 
     * @return null|string
     * Absolute path.
     */
    public function getCoverAbsolute()
    {
        return NULL === $this->getCover()
                ? NULL
                : $this->getUploadAbsolutePathPath() . '/' . $this->getCover();
    }

    /**
     * Set validation for max file size of 2 MB.
     * 
     * @Assert\File(maxSize="2M")
     */
    private $file;

    /**
     * Sets file.
     * 
     * @param UploadedFile $file
     */
    public function setFile(UploadedFile $file = NULL) 
    {
        $this->file =  $file;
    }

    /**
     * Get file.
     * 
     * @return UploadedFile
     */
    public function getFile()
    {
        return $this->file;
    }

    /**
     * 
     * Upload a cover file.
     */
    public function upload()
    {
        //file property can be empty
        if (NULL === $this->getFile()){
            return;
        }
        $filename=$this->getFile()->getClientOriginalName();

        //move the uploaded file to the target directory using the original name
        $this->getFile()->move(
                $this->getUploadAbsolutePath(),
                $filename);

        //set the cover
        $this->setCover($filename);

        //cleanup
        $this->setFile();
    }

    /**
     * @var string
     * 
     * @ORM\Column(name="Cover", type="string", length=255, nullable=true)
     */
    private $cover;


    /**
     * Set cover
     *
     * @param string $cover
     *
     * @return Events
     */
    public function setCover($cover)
    {
        $this->cover = $cover;

        return $this;
    }

    /**
     * Get cover
     *
     * @return string
     */
    public function getCover()
    {
        return $this->cover;
    }
    /**
     * @var \Vendor\MyBundle\Entity\Logins
     */
    private $loginid;

    /**
     * @var \Vendor\MyBundle\Entity\WishList
     */
    private $wishlistid;


    /**
     * Set loginid
     *
     * @param \Vendor\MyBundle\Entity\Logins $loginid
     *
     * @return Events
     */
    public function setLoginid(\Vendor\MyBundle\Entity\Logins $loginid = null)
    {
        $this->loginid = $loginid;

        return $this;
    }

    /**
     * Get loginid
     *
     * @return \Vendor\MyBundle\Entity\Logins
     */
    public function getLoginid()
    {
        return $this->loginid;
    }

    /**
     * Set wishlistid
     *
     * @param \Vendor\MyBundle\Entity\WishList $wishlistid
     *
     * @return Events
     */
    public function setWishlistid(\Vendor\MyBundle\Entity\WishList $wishlistid = null)
    {
        $this->wishlistid = $wishlistid;

        return $this;
    }

    /**
     * Get wishlistid
     *
     * @return \Vendor\MyBundle\Entity\WishList
     */
    public function getWishlistid()
    {
        return $this->wishlistid;
    }
}
以及控制器中的以下索引操作:

namespace Vendor\MyBundle\Controller;

use Symfony\Component\HttpFoundation\Request;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Vendor\MyBundle\Entity\Events;
use Vendor\MyBundle\Form\EventsType;

/**
 * Events controller.
 *
 * @Route("/sec/events")
 */
class EventsController extends Controller
{
    /**
     * Lists all Events entities.
     *
     * @Route("/", name="sec_events_index")
     * @Method("GET")
     */
    public function indexAction()
    {
        $em = $this->getDoctrine()->getManager();
        $user = $this->getUser();
        $events = $em->getRepository('VendorMyBundle:Events')->findBy(array('loginid' => $user->getLoginid()));

        return $this->render('events/index.html.twig', array(
            'events' => $events,
        ));
    }
}
但是,我被抛出错误:Unrecognized field:loginid,即使这是Events类中字段/属性的名称
我看了一下,我确实有代码,就像上面说的那样
我错过了什么?

任何帮助都将不胜感激

您缺少
$loginid
的一些ORM定义,因此事件表中没有列loginid


我假设您希望与
..\Entity\Logins
有一个多域或多个关联,因此您必须根据以下内容定义该关联:

小建议-在类中首先组织属性,然后组织方法。它更好,可读性更好,将来你会喜欢它的。谢谢,说得好。当我回到那个班时,我总是把它们弄丢是的,就是这样!谢谢
至于OneToMany,我不能添加它,我也不需要它,因为目标实体中的目标属性是ID属性,它不允许我在注释中添加该选项,对吗?简单地说-如果您不为属性定义ORM注释,它对原则是不可见的,并且该属性不会持久化到DB中(不管是简单的数据类型还是关联)。然后,当您想要在VendorMyBundle:Events repo中获取loginid时,没有任何选项…您必须选择-1)根据您的需要定义一些关联,2)如果您不想要关联,您必须手动设置$loginid,但在stat情况下,它必须与Logins类中的$id类型相同