我收到错误Syntax error or access violation: 1064 Syntax error near 'read = '1' WHERE id = 1' at line 1
这是我的控制器操作方法:
/**
* @Route("/show/{id}", name="pm_show", requirements={"id"="\d+"})
*/
public function show(Request $request, $id)
{
$this->initialize();
$user = $this->getUser();
$repository = $this->getDoctrine()->getRepository(Pm::class);
$messId = $id;
$messageUser = $repository->findByMessId($messId);
if ($messageUser[0]['read'] == 0)
{
$message = $repository->find($messageUser[0]['id']);
if (!$message) {
throw $this->createNotFoundException(
'No message found for id '.$messageUser[0]['id']
);
}
/**********************************************/
$message->setRead('1');
$this->getDoctrine()->getManager()->flush();
/**********************************************/
}
$this->addToTemplateArray(array (
'mess_id' => $messId,
'message' => $messageUser
));
return $this->render('pm/pm_show.html.twig', $this->templateArray);
}
我的实体:
<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* App\Entity\Pm
*
* @ORM\Table(name="pm")
* @ORM\Entity(repositoryClass="App\Repository\PmRepository")
*/
class Pm
{
/**
* @var integer $id
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
*
* @var App\Entity\User $sender
*
* @ORM\ManyToOne(targetEntity="App\Entity\User")
* @ORM\JoinColumn(name="sender", referencedColumnName="id")
*/
private $sender;
/**
*
* @var App\Entity\User $recipient
*
* @ORM\ManyToOne(targetEntity="App\Entity\User")
* @ORM\JoinColumn(name="recipient", referencedColumnName="id")
*/
private $recipient;
/**
* @var string $title
*
* @ORM\Column(name="title", type="string", length=100)
*/
private $title;
/**
* @var text $content
*
* @ORM\Column(name="content", type="text")
*/
private $content;
/**
* @var datetime $time
*
* @ORM\Column(name="time", type="datetime")
*/
private $time;
/**
* @var string $read
*
* @ORM\Column(name="read", type="string", length=1)
*/
private $read;
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set sender
*
* @param integer $sender
*/
public function setSender($sender)
{
$this->sender = $sender;
}
/**
* Get sender
*
* @return integer
*/
public function getSender()
{
return $this->sender;
}
/**
* Set recipient
*
* @param integer $recipient
*/
public function setRecipient($recipient)
{
$this->recipient = $recipient;
}
/**
* Get recipient
*
* @return integer
*/
public function getRecipient()
{
return $this->recipient;
}
/**
* Set title
*
* @param string $title
*/
public function setTitle($title)
{
$this->title = $title;
}
/**
* Get title
*
* @return string
*/
public function getTitle()
{
return $this->title;
}
/**
* Set content
*
* @param text $content
*/
public function setContent($content)
{
$this->content = $content;
}
/**
* Get content
*
* @return text
*/
public function getContent()
{
return $this->content;
}
/**
* Set time
*
* @param datetime $time
*/
public function setTime($time)
{
$this->time = $time;
}
/**
* Get time
*
* @return datetime
*/
public function getTime()
{
return $this->time;
}
/**
* Set read
*
* @param string $read
*/
public function setRead($read)
{
$this->read = $read;
}
/**
* Get read
*
* @return string
*/
public function getRead()
{
return $this->read;
}
}
我不知道为什么会出现此错误。我没有看到任何语法错误,并且尝试更新标题(例如我的Pm实体),并且它可以工作。然后问题仅在于读取列。也许有访问冲突,但我看不到。 我也尝试在数据库中手动更新,并且可以正常工作。感谢您的帮助。