Create a new delete_action object in Symfony 1.4 admin generator

I am using Symfony 1.4 / Doctrine message generator.

There is a list of questions here, and I would like to be able to execute a custom object_action for each of them.

I am looking to simulate the action of an object _delete, but do some calculations before that.

So, I created a new action:

  public function executeListDeleteAndRecalculate(sfWebrequest $request)
  {
    // Do the calculation

    // Then delete the question
  }

And I add it to my .yml generator:

object_actions:
    delete_and_recalculate: ~

the new action is displayed in the administrator generator, but the delete part does not work.

I tried a bunch of things to make it work:

  • Once all the calculations have been completed, I first tried to redirect the action questionActions/delete.
  • I also tried copying the code executeDeleteinto my new action.

But every time I get notorious

500 | | sfValidatorErrorSchema _csrf_token [.]

, , Symfony , .

, , , deleteAndRecalculate?

Edit:

, $request->checkCSRFProtection();, . , , .

+3
1

, delete CSRF.

, , . , delete javascript ( sf_method REST).

, CSRF , : http://en.wikipedia.org/wiki/Cross-site_request_forgery

, , method link_to, , lib/generator/sfModelGeneratorHelper.class.php line 32, , -gen.

$request->checkCSRFProtection() executeDeleteAndRecalculate , , .

, linkToDeleteAndRecalculate Helper ( lib/${YourModule}GeneratorHelper.class.php ) ( sfModelGeneratorHelper):

public function linkToDeleteAndRecalculate($object, $params)
{
  if ($object->isNew())
  {
    return '';
  }

  return '<li class="sf_admin_action_delete">'.link_to(__($params['label'], array(), 'sf_admin'), 'delete_and_recalculate', $object, array('method' => 'delete', 'confirm' => !empty($params['confirm']) ? __($params['confirm'], array(), 'sf_admin') : $params['confirm'])).'</li>';
}

, ( delete_and_recalculate , ) link_to.

delete_and_recalculate admin (, , generator.yml)

.

admin.delete_object, , , , : -)

+4

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


All Articles