简体   繁体   English

silex将表单数据传递到另一页?

[英]silex passing form data to another page?

I'm really new to silex and symfony. 我对Silex和Symfony真的很陌生。 This is my first foray into silex. 这是我第一次进军矽胶市场。 I've got code that created my form in my app.php file from a little hacking and copying and pasting from documentation. 我得到了一些代码,这些代码是通过一些黑客攻击以及文档的复制和粘贴在我的app.php文件中创建了表单的。

Now how do i pass this data to another page? 现在如何将这些数据传递到另一个页面?

I would like to create a page that just dumps the post/get array to give me an idea how to pass around get/post variables. 我想创建一个仅转储post / get数组的页面,以使我了解如何传递get / post变量。

Here's part of my app file: 这是我的应用程序文件的一部分:

<?php
/** /src/app.php */
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

    /**
     * Register new application
     */
    $app = new Application();
    // skip to the form part ...
        $app->match('/', function (Request $request) use ($app) {
            // some default data for when the form is displayed the first time
            $data = array(
                'name' => 'Your name',
                'email' => 'Your email',
            );

            $form = $app['form.factory']->createBuilder('form', $data)
                ->add('name')
                ->add('email')
                ->add('gender', 'choice', array(
                    'choices' => array(1 => 'male', 2 => 'female'),
                    'expanded' => true,
                ))
                ->getForm();

            if ('POST' == $request->getMethod()) {
                $form->bindRequest($request);

                if ($form->isValid()) {
                    $data = $form->getData();

                    // do something with the data

                    // redirect somewhere
                    return $app->redirect('completed');
                }
            }

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

Would i then create a page like so? 然后我会像这样创建一个页面吗?

<?php  // app.php  
    $app->match('complete') use function ($app) {
          // sorry psuedocode
         foreach ($REQUEST as $key=> $var) {
         echo "$key: $var";
         }
        }

You could try using a forward. 您可以尝试使用转发。 http://silex.sensiolabs.org/doc/usage.html#fowards http://silex.sensiolabs.org/doc/usage.html#fowards

// where params is the values from your POST
$subRequest = Request::create('/otherpage', 'GET', $params);

return $app->handle($subRequest, HttpKernelInterface::SUB_REQUEST);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM