Symfony Doctrine executeCreate generator generator

Thanks for any help with this, I'm very new to the Symfony platform, so I'm just trying to plunge into it.

I want to be able to intercept the submitted form from the administration area and change the data.

Here is what I have so far (in basic form).

/apps/backend/modules/proposition/actions/action.class.php

class propositionActions extends autoPropositionActions { public function executeCreate(sfWebRequest $request) { // modify the name $name = $request->getParameter('name'); $name = $name . ' is an idiot'; $request->setParameter('name', $name); return parent::executeCreate($request); } } 

My form contains a name field:

/apps/backend/modules/proposition/config/generator.yml

 generator: class: sfDoctrineGenerator param: model_class: Proposition theme: admin non_verbose_templates: true with_show: false singular: ~ plural: ~ route_prefix: proposition with_doctrine_route: true actions_base_class: sfActions config: actions: ~ form: display: [name, icon, overview, published] 

I'm not sure what you need this file, but it is definitely in HTML:

 <input type="text" id="proposition_name" name="proposition[name]"> 

When I submit the form, it just saves my name. I want him to keep my name adding "idiot".

Thank you very much

+4
source share
2 answers

I think you are on the right track for Peter, but you are modifying $request too late for it to have any effect.

You can do this modification of the input data in "doClean" in the form validation module .

Or, if you have special processing, it might make sense to override the generated processForm() function. Just copy it from cache/frontend/dev/modules/autoProposition/actions/actions.class.php to your apps/backend/modules/proposition/actions/action.class.php and start hacking.

+2
source

Why do this in your actions? I think the most appropriate place is the form itself.

You can change the value of any column by adding an update * Column Method:

 class PropositionForm extends BasePropositionForm { public function updateNameColumn($name) { return $name . ' is an idiot'; } } 

Note. If you do not want the idiot line to be added to other places where your form is used, you can subclass the original form and add your method there (for example, in AdminPropositionForm).

You can change the form used with the module created by the administrator by overloading the getFormClass () method in your module configuration class (offerGeneratorConfiguration). It should return the name of the form class that you want to use.

Note 2: You have access to the values โ€‹โ€‹of the form in different ways:

 $proposition = $request->getParameter('proposition', array()); $name = $proposition['name']; 
+2
source

Source: https://habr.com/ru/post/1336021/


All Articles