orm - 奇怪的错误 : [Semantical Error] line 0, col 75 靠近 'submit' :错误: 'submit' 未定义

标签 orm symfony doctrine-orm repository

我的 Controller 是:

  /**
   * @Route("/product/submit", name="product_submit") 
   * @Template("GaorenVendorsBundle:Product:index.html.twig")
   */
  public function submitAction()
  {
        $em = $this->getDoctrine()->getManager();
        $uid = $this->getUser()->getId();
        $em->getRepository( 'GaorenVendorsBundle:Product' )->updateStatus( $uid, Product::STATUS_FREE, Product::STATUS_PENDING );

        return $this->redirect( $this->generateUrl( 'product' ) );
  }

我的仓库是:

class ProductRepository extends EntityRepository
{

  public function updateStatus($uid, $status, $setter)
  {
        $st = $this->getEntityManager()->getRepository( 'GaorenVendorsBundle:Product' )
              ->createQueryBuilder( 'p' )
              ->update( 'GaorenVendorsBundle:Product', 'p' )
              ->set( 'p.status', ':setter' )
              ->where( 'p.status= :status AND p.user= :user' )
              ->setParameters( array(
                      'user' => $uid,
                      'status' => $status,
                      'setter' => $setter
              ) )
              ->getQuery()
              ->execute()

        return $st;
  }

Twig :

    <a class="btn btn-large btn-primary " href="{{ path('product_submit') }}">
        <i class="icon-plus icon-white"></i>
        {{ 'create a new entry'|trans }}
    </a>

当请求“提交”操作时,它会提示我:

[Semantical Error] line 0, col 75 near 'submit': Error: 'submit' is not defined.

“submit”与 Doctrine ORM 查询无关,为什么会出现在错误中?

最佳答案

是否有一条路线与上面的 /product/{id} 之类的内容相匹配?

这将与您的 /product/submit 路由匹配,并将 $id 视为字符串 "submit"。 Symfony 中第一个匹配的路线获胜。然后,如果您尝试从此 id 检索 Product 对象,则可能会引发此类错误。

解决方案是将提交操作移至处理 /product/{id} 路由的操作之上。

关于orm - 奇怪的错误 : [Semantical Error] line 0, col 75 靠近 'submit' :错误: 'submit' 未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11200321/

相关文章:

php - 从 Doctrine 开始。哪个版本好?

java - 使用 Hibernate 作为 ORM 机制的 Web 应用程序中的 L1 和 L2 缓存有什么区别?

php - 在 Symfony2 Controller 中获取表单值,子级不存在

php - Laravel - store() 方法突然不起作用

orm - 为什么 Doctrine 2 没有基本的验证方法来验证所有值是否适合实体属性?

java - Cassandra 阿喀琉斯 : One to many mapping

java - SQLiteConstraintException : How to map "no relationship" with a FOREIGN KEY in Room

php - php 中的 PDOException “could not find driver”

php - Symfony 3.4 没有要处理错误的元数据类

symfony - Doctrine2 命名查询