'错误:无效的PathExpression。必须是StateFieldPathExpression'学说中的错误

时间:2016-01-29 08:59:11

标签: symfony doctrine

我尝试连接两个表并使用doctrine查询构建器获取列值。

这是我的代码

public function getLatestProduct($amount) {
        $em = $this->container->get('doctrine.orm.entity_manager');

        $qb = $em->createQueryBuilder();

        $qb->select('p.id, p.category, p.productTitle, p.price, p.description, pi.imgUrl')
                ->from('EagleShopBundle:Products', 'p')
                ->leftJoin('EagleShopBundle:ProuctImage', 'pi', \Doctrine\ORM\Query\Expr\Join::WITH, 'pi.productId = p.id')
                ->orderBy('p.id', 'DESC')
                ->groupBy('p.id')
                ->setMaxResults($amount);

        return $qb->getQuery()->getResult();
    }

这就是我所说的

public function indexAction() {
        $latest = $this->getLatestProduct(8);
        $isfeatured = $this->getfeaturedProduct(8);

        return $this->render("EagleShopBundle:global:home.html.twig", array(
                    'image_path' => '/bundles/eagleshop/images/',
                    'latest_products' => $latest,
                    'isfeatured' => $isfeatured
        ));
    }

但是当我尝试称这种方法时,我遇到了这个问题,

  

[语义错误]第0行,第15列附近'类别,p.productTitle,':   错误:无效的PathExpression。必须是StateFieldPathExpression。

我认为此代码与问题有关,

  

$ qb->选择(' p.id,p.category,p.productTitle,p.price,p.description,   pi.imgUrl&#39)

这是我的产品实体

<?php

namespace Eagle\ShopBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * Products
 *
 * @ORM\Table(name="products", indexes={@ORM\Index(name="category", columns={"category"})})
 * @ORM\Entity
 */
class Products
{
    /**
     * @var string
     *
     * @ORM\Column(name="product_title", type="string", length=400, nullable=false)
     */
    private $productTitle;

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

    /**
     * @var float
     *
     * @ORM\Column(name="price", type="float", precision=10, scale=0, nullable=false)
     */
    private $price;

    /**
     * @var integer
     *
     * @ORM\Column(name="store_id", type="integer", nullable=false)
     */
    private $storeId;

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

    /**
     * @var integer
     *
     * @ORM\Column(name="stock", type="integer", nullable=false)
     */
    private $stock;

    /**
     * @var integer
     *
     * @ORM\Column(name="isfeatured", type="integer", nullable=false)
     */
    private $isfeatured;

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

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

    /**
     * @var integer
     *
     * @ORM\Column(name="online", type="integer", nullable=false)
     */
    private $online;

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

    /**
     * @var \Eagle\ShopBundle\Entity\ProductCategory
     *
     * @ORM\ManyToOne(targetEntity="Eagle\ShopBundle\Entity\ProductCategory")
     * @ORM\JoinColumns({
     *   @ORM\JoinColumn(name="category", referencedColumnName="id")
     * })
     */
    private $category;



    /**
     * Set productTitle
     *
     * @param string $productTitle
     * @return Products
     */
    public function setProductTitle($productTitle)
    {
        $this->productTitle = $productTitle;

        return $this;
    }

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

    /**
     * Set description
     *
     * @param string $description
     * @return Products
     */
    public function setDescription($description)
    {
        $this->description = $description;

        return $this;
    }

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

    /**
     * Set price
     *
     * @param float $price
     * @return Products
     */
    public function setPrice($price)
    {
        $this->price = $price;

        return $this;
    }

    /**
     * Get price
     *
     * @return float 
     */
    public function getPrice()
    {
        return $this->price;
    }

    /**
     * Set storeId
     *
     * @param integer $storeId
     * @return Products
     */
    public function setStoreId($storeId)
    {
        $this->storeId = $storeId;

        return $this;
    }

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

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

        return $this;
    }

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

    /**
     * Set stock
     *
     * @param integer $stock
     * @return Products
     */
    public function setStock($stock)
    {
        $this->stock = $stock;

        return $this;
    }

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

    /**
     * Set isfeatured
     *
     * @param integer $isfeatured
     * @return Products
     */
    public function setIsfeatured($isfeatured)
    {
        $this->isfeatured = $isfeatured;

        return $this;
    }

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

    /**
     * Set createdAt
     *
     * @param \DateTime $createdAt
     * @return Products
     */
    public function setCreatedAt($createdAt)
    {
        $this->createdAt = $createdAt;

        return $this;
    }

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

    /**
     * Set updatedAt
     *
     * @param \DateTime $updatedAt
     * @return Products
     */
    public function setUpdatedAt($updatedAt)
    {
        $this->updatedAt = $updatedAt;

        return $this;
    }

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

    /**
     * Set online
     *
     * @param integer $online
     * @return Products
     */
    public function setOnline($online)
    {
        $this->online = $online;

        return $this;
    }

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

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

    /**
     * Set category
     *
     * @param \Eagle\ShopBundle\Entity\ProductCategory $category
     * @return Products
     */
    public function setCategory(\Eagle\ShopBundle\Entity\ProductCategory $category = null)
    {
        $this->category = $category;

        return $this;
    }

    /**
     * Get category
     *
     * @return \Eagle\ShopBundle\Entity\ProductCategory 
     */
    public function getCategory()
    {
        return $this->category;
    }
}

0 个答案:

没有答案