i modal handle $doctrine->presist($modal); saving purpose. possible?
following example.
modal class made out of config key , value fields.
amazonss3setting.php modal
<?php namespace eggs\businesspanelbundle\form\model; use eggs\corebundle\entity\business; use symfony\component\validator\constraints 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 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 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 keep $em->presist($storage) , $em->flush(); same , handle data save , update modal class. possible? or there alternative way this?
since table build key , value fields, not want manually set these names inside controller, prefer outside, can later change modal or other classes , automatically change inside controller method.
in opinion on of best approachs create entity repository can keep controller clean.
same , handle data save , update modal class
you want handle update model class ? or did understood wrong.
Comments
Post a Comment