Symfony 2 syntax Error

时间:2015-09-14 16:17:59

标签: symfony doctrine-orm

Having some troubles with Symfony 2. I'm new in Symfony 2. Trying to get some rows from table with my entitiy.

Here is the Entity

namespace AppBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity
 * @ORM\Table(name="articles")
 */
class Article
{
    /**
     * @var integer $id
     *
     * @ORM\Id
     * @ORM\Column(name="id", type="integer")
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;

    /**
     * @ORM\Column(type="string" name="title")
     */
    protected $title;


    /**
     * @ORM\Column(type="int" name="author_id")
     */
    protected $authorId;

    /**
     * @ORM\Column(type="datetime" name="creation_date")
     */
    protected $creationDate;

    /**
     * @ORM\Column(name="string")
     */
    protected $content;

    public function getId()
    {
        return $this->id;
    }

    public function getTitle()
    {
        return $this->title;
    }

    public function getAuthorId()
    {
        return $this->authorId;
    }

    public function getCreationDate()
    {
        return $this->creationDate;
    }

    public function getContent()
    {
        return $this->content;
    }
}

the Controller

$query = $em->createQuery(
        'SELECT a FROM AppBundle:Article a'
        );

        $article = $query->getResult();

Getting Error

[Syntax Error] Expected Doctrine\Common\Annotations\DocLexer::T_CLOSE_PARENTHESIS, got 'name' at position 26 in property AppBundle\Entity\Article::$title.

I have nothing on 26 row. Anybody can tell me whats wrong?

Thank you!

2 个答案:

答案 0 :(得分:3)

错误信息只是明确的......

我认为你应该有一个逗号:

/**
 * @ORM\Column(type="string", name="title")
 */
protected $title;

BTW,name在这里没用。

答案 1 :(得分:0)

这些属性应该用逗号分隔。只有当您使用的变量与列名不同时,才应使用名称。例如,您在DB中有some_var,但必须在代码中使用$ someVar。