Zend Framework 2 - Doctrine 2错误消息 [英] Zend Framework 2 - Doctrine 2 Error message

查看:112
本文介绍了Zend Framework 2 - Doctrine 2错误消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试从Zend Framework 2向Album Module添加更多的灵活性。在这个过程中,我一直在尝试为其中一个表单字段设置一个验证器,特别是对于专辑名称,在我的例子中,列名称我的数据库是标题。



我已经从我之前发布的一个答案中跟踪验证部分,可以在其中



I在我的albumcontroller类中一直使用这个类:

 <?php 

命名空间Album\Controller;

使用Zend\Mvc\Controller\AbstractActionController;
使用Zend\View\Model\ViewModel;
使用Album \Entity\Album\Album;
使用Album \Form\AlbumForm;
使用Album \Model\Album\AlbumExists;
使用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()&&&                          形状配合>的getData());
$ this-> getEntityManager() - > persist($ album);
$ this-> getEntityManager() - > flush();

return $ this-> redirect() - > toRoute('album');
}
}
返回数组('form'=> $ form);
}

当我输入已经在数据库中的相册名称/标题时,它会抛出以这种方式出现错误:


 执行期间发生错误;请稍后再试。 
附加信息:
Doctrine\ORM\Query\QueryException

文件:
C:\vendor\doctrine\orm\lib\\ \\Doctrine\ORM\Query\QueryException.php:69

消息:
参数号无效:绑定变量的数量与令牌数不匹配。


任何想法,我犯错误?

解决方案

如果您使用我的类,但没有修改该部分,则在查询中缺少WHERE条件。 / p>

在类中,参数:value 是绑定的,因此您必须在查询中使用此参数(例如 WHERE a.title =:value )。


I have been trying to add more flexibilities to the Album Module from Zend Framework 2. In that process I have been trying to set a validator for one of the form fields especially for the album name which in my case the column name in my database is title.

I have been following the validation part from one of the previous answers to my post, which can be found here

I have been using that class in my albumcontroller class in this fashion:

<?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);
    }

When I enter a album name/title which is already in the database it throws an error in this fashion:

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.

Any idea where Im making a mistake?

解决方案

In case you're using "my" class and haven't modified that part, you're missing the WHERE condition in your query.

In the class, a parameter :value is bound, so you have to use this parameter in your query (e.g. WHERE a.title = :value).

这篇关于Zend Framework 2 - Doctrine 2错误消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆