我想在我的网站上保存我的用户搜索。这就是为什么我有一个类用户并且我想创建搜索类。我已经做到了:
class Search
{
public function __construct()
{
$this->searched_date = new \Datetime();
}
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue
*/
private $id;
/**
* @ORM\Id
* @ORM\ManyToOne(targetEntity="test\UserBundle\Entity\User")
*/
private $user;
/**
* @ORM\Column(name="termsearch", type="string", length=255, nullable="true")
*/
private $termsearch;
/**
* @ORM\Column(name="goodtitle", type="string", length=255, nullable="true")
*/
private $goodtitle;
/**
* @ORM\Column(name="searched_date", type="datetime")
*/
private $searched_date;
/**
* Set termsearch
*
* @param text $termsearch
*/
public function setTermsearch($termsearch)
{
$this->termsearch = $termsearch;
}
/**
* Get termsearch
*
* @return text
*/
public function getTermsearch()
{
return $this->termsearch;
}
/**
* Set searched_date
*
* @param datetime $searchedDate
*/
public function setSearchedDate($searchedDate)
{
$this->searched_date = $searchedDate;
}
/**
* Get searched_date
*
* @return datetime
*/
public function getSearchedDate()
{
return $this->searched_date;
}
/**
* Set user
*
* @param test\UserBundle\Entity\User $user
*/
public function setUser(\test\UserBundle\Entity\User $user)
{
$this->user = $user;
}
/**
* Get user
*
* @return test\UserBundle\Entity\User
*/
public function getUser()
{
return $this->user;
}
/**
* Set goodtitle
*
* @param text $goodtitle
*/
public function setGoodtitle($goodtitle)
{
$this->goodtitle = $goodtitle;
}
/**
* Get goodtitle
*
* @return text
*/
public function getGoodtitle()
{
return $this->goodtitle;
}
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
}
我想这样插入:
$em = $this->getDoctrine()->getEntityManager();
$user = $em->getRepository('TestUserBundle:User')->find($currentuser->getID());
$search = new Search();
$search->setUser($user);
$search->setTermsearch($termsearch);
$search->setGoodtitle($goodtitle);
$em->persist($search);
$em->flush();
不幸的是我有这个错误:
SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens (500 Internal Server Error)
在堆栈中,我们可以发现:
INSERT INTO s_search (user_id, termsearch, goodtitle, searched_date) VALUES (?, ?, ?, ?) ({"1":"c2c","2":"C2C Down The Road","3":{"date":"2012-10-31 00:18:47","timezone_type":3,"timezone":"Europe\/Paris"}})
我不知道如何创建此类搜索...感谢您的帮助!