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 8683249
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T21:59:23+00:00 2026-06-12T21:59:23+00:00

controller public function indexAction(Request $request) { $user = $this->container->get(‘security.context’)->getToken()->getUser(); $owner = $user->getId(); $first =

  • 0

controller

public function indexAction(Request $request)
{
    $user = $this->container->get('security.context')->getToken()->getUser();
    $owner = $user->getId();

    $first = new First();
    $first->setOwner($owner);

    $second = new Second();
    $second->setOwner($owner);
    $second->setFirst($first);

    $form = $this->createForm(new SecondType(), $second);

    if ($request->getMethod() == 'POST') {
        $form->bindRequest($request);

        if ($form->isValid()) {
            $em = $this->get('doctrine')->getEntityManager();
            $em->persist($first);
            $em->persist($second);
            $em->flush();
        }
    }

    return $this->render('MySampleBundle:Home:index.html.twig', array(
        'form' => $form->createView(),
    ));

}

ORM Yaml

My\SampleBundle\Entity\First:
    type: entity
    table: first
    id:
        id:
            type: integer
            generator: { strategy: AUTO }
    fields:
        title:
            type: string
        date_created:
            type: datetime
        date_edited:
            type: datetime
        owner:
            type: integer
    lifecycleCallbacks:
        prePersist: [ prePersist ]
        preUpdate: [ preUpdate ]
    oneToMany:
        reviews:
            targetEntity: Second
            mappedBy: review

My\SampleBundle\Entity\Second:
    type: entity
    table: second
    id:
        id:
            type: integer
            generator: { strategy: AUTO }
    fields:
        review:
            type: string
        date_created:
            type: datetime
        date_edited:
            type: datetime
        owner:
            type: integer
    lifecycleCallbacks:
        prePersist: [ prePersist ]
        preUpdate: [ preUpdate ]
    manyToOne:
        first:
            targetEntity: First
            inversedBy: reviews
            joinColumn:
                name: first_id
                referencedColumnName: id

Form/Type

class FirstType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder->add('title', 'text');
    }

    public function getDefaultOptions(array $options)
    {
        return array(
            'data_class' => 'My\SampleBundle\Entity\First',
        );
    }

    public function getName()
    {
        return 'first';
    }
}

class SecondType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder->add('first', new FirstType());
        $builder->add('review', 'textarea');
    }

    public function getName()
    {
        return 'second';
    }
}

Validation.yml

My\SampleBundle\Entity\First:
    properties:
        title:
            - NotBlank: ~
            - MinLength: 2

My\SampleBundle\Entity\Second:
    properties:
        review:
            - NotBlank: ~
            - MinLength: 14

The created form works normally.
However, only the validation does not work normally.

If it performs individually, validation will work normally.

$form = $this->createForm(new FirstType(), $first);

However, if it is in a Entity Relationships/Associations state, the first validation will not work.The First’s title property in one character will be registered.

How can I manage to achieve that?

  • 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-12T21:59:24+00:00Added an answer on June 12, 2026 at 9:59 pm

    Symfony 2.1+ doesn’t automatically validate all the embedded objects. You need to put the Valid constraint on the first field to make it validate as well:

    My\SampleBundle\Entity\Second:
        properties:
            first:
                - Valid: ~
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this in my Controller. public function delete($id) { if($this->request->is('get')) { throw new
Take for example the following controller/action: public function indexAction() { return $this->render('TestBundle:TestController:index.html.twig'); } I
Zend Form is not my friend today! This works :- Controller:- public function indexAction()
public function process(Zend_Controller_Request_Abstract $request) { $this->first_name = $this->sanitize($request->getPost('first_name')); .... } My question is $request
I have 2 functions/methods in the same controller in CodeIgniter like this: public function
I create a simple form with multiple rows: Controller: public function indexAction() { $repository
Using following controller: class mydvbController extends Zend_Controller_Action { public function indexAction() { } public
I have a method in my controller public function download($filepath){ $download_path = $_SERVER['DOCUMENT_ROOT']. mediabox/import;
I have the following controller: class Tests extends CI_Controller { public function update_record_test() {
See the following code of the <?php class DefaultController extends Controller { public function

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.