我正在做symfony 2教程 - Doctrine和数据库.
我在Entity/Pages.php中创建了Pages.php文件
<?php
namespace Dproc\MainBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* @IgnoreAnnotation("fn")
*
*/
/**
* @ORM\Entity
* @ORM\Table(name="pages")
*/
class Pages
{
/**
* @ORM\ID
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $ID;
/**
* @ORM\Column(type="text")
*/
protected $page_title;
/**
* @ORM\Column(type="text")
*/
protected $page_content;
/**
* @ORM\Column(type="text")
*/
protected $page_category;
}
Run Code Online (Sandbox Code Playgroud)
现在我正在尝试使用此命令为此类生成setter和getter.
php app/console doctrine:generate:entities Dproc/MainBundle/Entity/Pages
Run Code Online (Sandbox Code Playgroud)
它说 :
[Doctrine\Common\Annotations\AnnotationException]
[Semantical Error] The annotation "@Doctrine\ORM\Mapping\ID" in property Dp
roc\MainBundle\Entity\Pages::$ID does not exist, or could not be auto-loade …Run Code Online (Sandbox Code Playgroud) 我收到了这个错误
DprocMainBundle中不存在键为"0"的数组的"getPageTitle"键:Dproc:第2行的single.html.twig
第2行: {{ page.getPageTitle }}
我的实体文件
<?php
namespace Dproc\MainBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* @IgnoreAnnotation("fn")
*
*/
/**
* @ORM\Entity
* @ORM\Table(name="pages")
*/
class Pages
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $Id;
/**
* @ORM\Column(name="page_title", type="text")
*/
protected $pageTitle;
/**
* @ORM\Column(name="page_content", type="text")
*/
protected $pageContent;
/**
* @ORM\Column(name="page_category", type="text")
*/
protected $pageCategory;
/**
* Get Id
*
* @return integer
*/
public function getId()
{
return $this->Id;
}
/**
* Set page_title
* …Run Code Online (Sandbox Code Playgroud) 我正在使用Symfony/Doctrine.我正在尝试从表中选择最后4行,但我得到错误.
$em = $this->getDoctrine()->getEntityManager();
$query = $em->createQuery(
'SELECT c FROM DprocMainBundle:Courses c ORDER BY id DESC LIMIT 4'
);
$course = $query->getResult();
Run Code Online (Sandbox Code Playgroud)
这是我的查询但它显示错误.
预期结束字符串,得到'LIMIT'
我应该如何使用限制,并获得最后4行?
谢谢!
您好我正在尝试按标题选择
实体\ Pages.php
<?php
namespace Dproc\MainBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* @IgnoreAnnotation("fn")
*
*/
/**
* @ORM\Entity
* @ORM\Table(name="pages")
*/
class Pages
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $Id;
/**
* @ORM\Column(type="text")
*/
protected $page_title;
/**
* @ORM\Column(type="text")
*/
protected $page_content;
/**
* @ORM\Column(type="text")
*/
protected $page_category;
/**
* Get Id
*
* @return integer
*/
public function getId()
{
return $this->Id;
}
/**
* Set page_title
*
* @param string $pageTitle
* @return Pages …Run Code Online (Sandbox Code Playgroud)