Symfony2模态持续存在

I would like to modal to handle $doctrine->presist($modal); for saving purpose. Is this possible?

Following is the example.

Modal class made out of config key and value fields.

AmazonsS3Setting.php as Modal

<?php
namespace Eggs\BusinessPanelBundle\Form\Model;

use Eggs\CoreBundle\Entity\Business;
use Symfony\Component\Validator\Constraints as Assert;

class AmazonS3Setting
{
    private $storageAwsAccessKey;
    private $storageAwsSecretKey;
    private $storageAwsBucketName;

    private $business;

    /**
     * @param Business $business
     */
    public function __construct (Business $business)
    {
        $this->business = $business;

        $this->storageAwsAccessKey = $business->getConfigValueByKey('storageAwsAccessKey');
        $this->storageAwsSecretKey = $business->getConfigValueByKey('storageAwsSecretKey');
        $this->storageAwsBucketName = $business->getConfigValueByKey('storageAwsBucketName');
    }

    /**
     * @return mixed
     */
    public function getStorageAwsAccessKey ()
    {
        return $this->storageAwsAccessKey;
    }

    /**
     * @param mixed $storageAwsAccessKey
     */
    public function setStorageAwsAccessKey ($storageAwsAccessKey)
    {
        $this->storageAwsAccessKey = $storageAwsAccessKey;
    }

    /**
     * @return mixed
     */
    public function getStorageAwsSecretKey ()
    {
        return $this->storageAwsSecretKey;
    }

    /**
     * @param mixed $storageAwsSecretKey
     */
    public function setStorageAwsSecretKey ($storageAwsSecretKey)
    {
        $this->storageAwsSecretKey = $storageAwsSecretKey;
    }

    /**
     * @return mixed
     */
    public function getStorageAwsBucketName ()
    {
        return $this->storageAwsBucketName;
    }

    /**
     * @param mixed $storageAwsBucketName
     */
    public function setStorageAwsBucketName ($storageAwsBucketName)
    {
        $this->storageAwsBucketName = $storageAwsBucketName;
    }
}

AmazonsS3SettingType.php as Form Type

<?php

namespace Eggs\BusinessPanelBundle\Form;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

class AmazonS3SettingType extends AbstractType
{
    /**
     * @param FormBuilderInterface $builder
     * @param array $options
     */
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('storageAwsAccesskey', 'text', ['label' => 'Access Key'])
            ->add('storageAwsSecretkey', 'text', ['label' => 'Secret Key'])
            ->add('storageAwsBucketname', 'text', ['label' => 'Bucket Name'])
            //->add('baseurl', 'text', ['label' => 'Bucket Base Url', 'help' => 'your-business-account.s3.amazonaws.com'])
        ;
    }

    /**
     * @param OptionsResolver $resolver
     */
    public function configureOptions(OptionsResolver $resolver)
    {
        $resolver->setDefaults(array(
            'data_class' => 'Eggs\BusinessPanelBundle\Form\Model\AmazonS3Setting'
        ));
    }

    /**
     * @return string
     */
    public function getName()
    {
        return 'business_amazons3setting';
    }
}

Controller method for settings

/**
     * @Route("/storage", name="business_setting_storage")
     * @Template("@BusinessPanel/Setting/storageS3.html.twig")
     */
    public function storageAction(Request $request)
    {
        $business = $this->getUser();

        $storage = new AmazonS3Setting($business);

        $form = $this->createForm(New AmazonS3SettingType(), $storage)->add('Save', 'submit');

        $form->handleRequest($request);

        if ($form->isValid())
        {
            $em = $this->getDoctrine()->getManager();
            $em->persist($storage);
            $em->flush();

            $this->addFlash('success', 'Saved Successfully');
        }

        return [
            'form' => $form->createView()
        ];
    }

I would like to keep $em->presist($storage) and $em->flush(); same like this and handle data save and update from modal class. is this possible? or is there alternative way to do this?

Since my table is build with key and value only fields, I would not want to manually set these names inside controller, I would prefer outside, so I can later change modal or other classes and it will automatically change inside controller method.

In my opinion on of the best approachs would be to create an Entity Repository then you can keep your controller clean.

same like this and handle data save and update from modal class

You want to handle the update from the Model class ? Or did I understood wrong.