Silex - get right condionals in finish middleware

坚强是说给别人听的谎言 提交于 2019-12-12 04:32:49

问题


I want to create a pdf file out of some route-dependant data

{http://example.com/products/123/?action=update}

$app->finish(function (Request $request, Response $response) {

    // Make a pdf file, only if:
    // - the route is under  /products/
    // - the action is update
    // - the subsequent ProductType form isSubmitted() and isValid()
    // - the 'submit' button on the ProductType form isClicked()

});

As a normal form submission process I have:

public function update(Application $app, Request $request)
{
    $form = $app['form.factory']->create(ProductType::class, $product);

    $form->handleRequest($request);

    if ($form->isSubmitted() && $form->isValid()) {

        if (!$form->get('submit')->isClicked()) {
            return $app->redirect('somewhere');
        }

        $product = $form->getData();

        $app['em']->persist($product);
        $app['em']->flush();

        return $app->redirect('product_page');
    }

    return $app['twig']->render('products/update.html.twig', array(
        'form' => $form->createView(),
    ));
}

Questions:

  1. Should I duplicate all of the conditionals in finish middleware?
  2. How to access the Product entity in finish middleware?

Consider having multiple resource types like Products, Services, Users, ...

来源:https://stackoverflow.com/questions/41562964/silex-get-right-condionals-in-finish-middleware

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!