Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8581581
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T21:05:17+00:00 2026-06-11T21:05:17+00:00

I am new to the Symfony 2 web framework, and am struggling with a

  • 0

I am new to the Symfony 2 web framework, and am struggling with a very basic validation task. I have an entity model Post that has a member slug, which I use to build the link to the post. In Post.orm.yml I defined unique: true and want to include this constraint as a validator as well.

I have created a file validation.yml:

# src/OwnBundles/BlogpostBundle/Resources/config/validation.yml

OwnBundles\BlogpostBundle\Entity\Post:
    properties:
        slug:
            - NotBlank: ~
    constraints:
        - Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity: slug

The creation function in my controller is quite simple:

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(),
        )
    );
}

The basic pageflow works fine, I can add posts and see them, but if I duplicate a post title to test my validation, it throws an exception: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'duplicate-slug' for key 'UNIQ_FAB8C3B3989D9B62'. I have been scanning through documentation for quite some time now, but I was not able to find out why my $form->isValid() returns true.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T21:05:18+00:00Added an answer on June 11, 2026 at 9:05 pm

    Did you enable validation in app/config/config.yml ?

    ...
    
    framework:
        ...
        validation:    { enabled: true }
        ...
    
    ...
    

    and if you want to define validation with annotations too, you have to both enable validation and annotation validation :

    ...
    
    framework:
        ...
        validation:    { enabled: true, enable_annotations: true }
        ...
    
    ...
    

    And then don’t forget clear the app/cache directory.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to Symfony. Is my understanding correct that the User class is actually
I am very new to symfony. In other languages like java and others I
I am new to symfony. I have created a registration form using the code:
I'm pretty new to the Symfony Framework and currently searching for the Best-Practice way
I'm using Symfony 2.0.9 to build a new web site. Yesterday the newer version
i am trying to setup a new symfony framework project on ubuntu by following
I've got a very old php application (1999) that has been worked on during
I'm new to version 2 of the Symfony framework. I made some projects with
EDIT: Yields that there is already new PHP framework written as extension. http://code.google.com/p/yafphp ,
Im new to symfony and have some simple questions. I am trying to understand

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.