大佬教程收集整理的这篇文章主要介绍了php – YML验证文件被忽略,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
# src/OwnBundles/BlogpostBundle/resources/config/validation.yml OwnBundles\BlogpostBundle\Entity\Post: properties: slug: - NotBlank: ~ consTraints: - Symfony\Bridge\Doctrine\Validator\ConsTraints\UniqueEntity: slug
我的控制器中的创建功能非常简单:
public function addAction(request $request) { $post = new Post(); $form = $this->createForm(new PostType(),$post); if($request->getmethod() == 'POST') { $form->bind($request); if($form->isValid()) { $em = $this->getDoctrine()->getManager(); $em->persist($post); $em->flush(); return $this->redirect( $this->generateUrl('own_bundles_blogpost_homepage') ); } } return $this->render( 'OwnBundlesBlogpostBundle:Default:add.html.twig',array( 'title' => 'Add new blogpost','form' => $form->createView(),) ); }
基本的页面流工作正常,我可以添加帖子并看到它们,但是如果我复制一个标题来测试我的验证,它会抛出一个异常:sqlSTATE [23000]:完整性约束违规:1062重复条目“重复插入”键’UNIQ_FAB8C3B3989D9B62′.我一直在扫描文档已经有一段时间了,但是我无法找出为什么我的$form-> isValid()返回true.
... framework: ... validation: { enabled: true } ... ...
并且如果要使用注释定义验证,则必须同时启用验证和注释验证:
... framework: ... validation: { enabled: true,enable_Annotations: true } ... ...
然后不要忘记清除app / cache目录.
以上是大佬教程为你收集整理的php – YML验证文件被忽略全部内容,希望文章能够帮你解决php – YML验证文件被忽略所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。