我一直在試圖從Zend Framework 2向Album Module添加更多的靈活性。在這個過程中,我一直試圖爲表單字段之一設置一個驗證器,尤其是專輯名稱在我的情況下,我的數據庫中的列名稱是標題。Zend Framework 2 - Doctrine 2錯誤消息
我一直跟着驗證部分從以前的答案,我的帖子之一,它可以發現我一直在使用這個類在我albumcontroller類以這種方式here
:
<?php
namespace Album\Controller;
use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
use Album\Entity\Album\Album;
use Album\Form\AlbumForm;
use Album\Model\Album\AlbumExists;
use Doctrine\ORM\EntityManager;
class AlbumController
extends AbstractActionController
{
public function addAction()
{
$form = new AlbumForm();
$form->get('submit')->setAttribute('value', 'Add');
$query = "SELECT a.title FROM Album\Entity\Album\Album a";
$albumExists = new AlbumExists($this->getEntityManager(), $query, 'title');
$request = $this->getRequest();
if ($request->isPost())
{
$album = new Album();
$form->setInputFilter($album->getInputFilter());
$form->setData($request->getPost());
$title = $this->getRequest()->getPost('title');
if ($form->isValid() && $albumExists->isValid($title))
{
$album->populate($form->getData());
$this->getEntityManager()->persist($album);
$this->getEntityManager()->flush();
return $this->redirect()->toRoute('album');
}
}
return array('form' => $form);
}
當我輸入專輯名稱/標題這是已經在數據庫中,它拋出以這種方式錯誤:
An error occurred during execution; please try again later. Additional information: Doctrine\ORM\Query\QueryException File: C:\vendor\doctrine\orm\lib\Doctrine\ORM\Query\QueryException.php:69 Message: Invalid parameter number: number of bound variables does not match number of tokens.
任何想法我在哪裏犯了一個錯誤?
不要害怕投票 –