Php 如何在提交后检索get请求值

Php 如何在提交后检索get请求值,php,symfony,Php,Symfony,我正在处理一个Symfony 3项目,并试图从控制器操作中的请求中检索一个值(bedroomid) $bedroomid = $request->query->get('bedroomid'); 这很好用。请注意,这是在($form->isSubmitted()&&&$form->isValid())条件之前。问题是在我提交表单之后,$request->query->get('bedroomid')返回空值。我需要此值将其传递给另一个操作,如下所示: $url = $this-&g

我正在处理一个Symfony 3项目,并试图从控制器操作中的请求中检索一个值(
bedroomid

$bedroomid = $request->query->get('bedroomid');
这很好用。请注意,这是在($form->isSubmitted()&&&$form->isValid())条件之前。问题是在我提交表单之后,
$request->query->get('bedroomid')返回空值。我需要此值将其传递给另一个操作,如下所示:

$url = $this->generateUrl('epita_housing_orders_show', array('id' => $id, 'bedroom'=>$bedroomid));
        $response = new RedirectResponse($url);
         return $response;
有什么想法吗

编辑:

以下是我的控制器操作:

/**
 * @Route("/booking/{id}", requirements={"id" = "\d+"}, name="studentbooking")
 */
public function studentBookingAction(Request $request, $id) {

    $em = $this->getDoctrine()->getManager();
    $user = $this->get('security.token_storage')->getToken()->getUser();      
    $role = $user->getRoles()[0];
    $listing = $em->getRepository('EpitaHousingBundle:Listing')->findOneBy(array('id'=>$id));

    $booking = new Booking($em, $id);
    $form = $this->createForm(BookingType::class, $booking);
    $form->handleRequest($request);
    $bedroomid = $request->query->get('bedroomid');
    $selectedbedroom = $em->getRepository('EpitaHousingBundle:Bedroom')->findOneBy(array('id'=>$bedroomid));

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

      if ($listing->getPropertytype()->getId() == 1) {
         $booking->setListing($listing);
         $em->persist($booking);
         $em->flush();
         $url = $this->generateUrl('epita_housing_orders_show', array('id' => $id));
        }
      else {
         $booking->setBedroom($selectedbedroom);
         $em->persist($booking); 
         $em->flush();
         $url = $this->generateUrl('epita_housing_orders_show', array('id' => $id, 'bedroom'=>$bedroomid));
      }
     $response = new RedirectResponse($url);
     return $response;
    } 
    return $this->render('EpitaHousingBundle:Student:confirmbookingpage.html.twig', array(
        'id'=>$id,
        'form' => $form->createView(),
        'listing' => $listing,
        'bedroomid' => $bedroomid,
    ));
}
confirmbookingpage.html.twig

{% extends 'EpitaHousingBundle::layout.html.twig' %}
{% trans_default_domain 'FOSUserBundle' %}
{% form_theme form 'EpitaHousingBundle:Form:fields.html.twig' %}

{% block content %}
   <div class="container text-center">   
       <style>
             .error-message{
                color: red;
            }
        </style> 
    <div class="row content"> 
         <div class="col-sm-1"> </div>  
        <div class="col-sm-10 well well-sm">          
        <div class="impinst" style="background-color:#9b3163; color:white;">
            <b> <u>Important Instructions</u> </b> 
        </div>    

        <div class="row">
          <div class="col-sm-12" align="left">  
            <p>  
                The booking service is available to EPITA International Department Students only. 
                This is a free service from the airport to the EPITA campus and surrounding areas.</p>
            <p>Please do not fill this form if:</p>
            <ul>
                <li>You have not yet booked your flight tickets.</li>
                <li>You arrive within the next 72 hours. The airport pickup request must be made atleast 
                    72 hours before the request time.</li>
                <li>You do not want to use the airport pickup service.</li>
            </ul>
            <br>  
            <p>Please note:</p>
            <ul>
                <li>     
                    We may be unable to process your application for airport pickup if you request for a pickup on a non working day(weekends,
                    <br> National Holidays) or between 6PM and 8AM(any day). In such scenarios, we will inform you about the non-availability and provide <br> you with some alternatives. </li> 
                <li style="color:red;">You can cancel (due to technical issues: flight cancelled etc.) not less than 6 hours prior to your arrival time in Paris. If you do not<br>
                    show up at the airport or cancel too late, an 80-euros fee will be automatically charged.</li>   
                </ul>
            <br> 
                <p>For any questions, please do not hesitate to contact us at international@epita.fr</p>   
            </div> 
        </div>  
        <br>
        <div class="impinst" style="background-color:#9b3163; color:white;">
            <b> <u>Booking Details</u> </b> 
        </div> 
        <br><br> 
        {{ form_start(form, {'method': 'post', 'action': path('studentbooking', {'id': id }), 'attr': {'class': 'studentbooking','novalidate': 'novalidate'}}) }}              
        <div class="row">
            <div class="col-sm-2 text-left">{{ form_label(form.arrivaldate, 'Booking From') }}</div>
            <div class="col-sm-3">{{ form_widget(form.arrivaldate) }}</div> 
            <div class="col-sm-7 text-left">{{ form_errors(form.arrivaldate) }}</div> 
        </div>         
        <br>
        <div class="row">
            <div class="col-sm-2 text-left">{{ form_label(form.bookeduntill, 'Booking Till') }}</div>
            <div class="col-sm-3">{{ form_widget(form.bookeduntill) }}</div>
            <div class="col-sm-7 text-left">{{ form_errors(form.bookeduntill) }}</div> 
        </div>   
        <br>    
        <div class="row">
            <div class="col-sm-2 text-left"><b>Amount to be paid</b></div>
            <div class="col-sm-2"><input type="text" name="rent" style="width:110%;margin-left:35px;" value="250" disabled="disabled"/></div>
            <div class="col-sm-2">Euros</div> 

        </div>       
        <br>  
        <div class="row">
        <div class="col-sm-12 text-left">        
            <b> By paying the booking fee, you will bring to an end to the process of your online booking. Your application will then be
            transferred to our board of examiners for processing.(You will not be able to modify your booking anymore)</b>          
        </div>
        </div>     
        <br> 

       {% if listing.propertytype.id == 1 %}
      <a href="{{ path('epita_housing_orders_show', {'listing':id,'id': id }) }}"> 
          <button type="submit" name="confirm" value="Confirm" class="btn btn-primary">Confirm</button> 
      </a>  
      {% else %}
      <a href="{{ path('epita_housing_orders_show', {'bedroom' : bedroomid, 'id': id }) }}"> 
          <button type="submit" name="confirm" value="Confirm" class="btn btn-primary">Confirm</button> 
      </a>    
      {% endif %}

        &nbsp;&nbsp;  
        <a href="{{ path('studentlistingview', {'id': id }) }}">    
                    <input type="submit" name = "cancel" value="Cancel" class="btn btn-primary"/> 
        </a> 
                    <input type="hidden" name = "bedroomid" value={{bedroomid}}/>
        {{ form_end(form) }}
        </div>      
        </div>          
   </div>           
{% endblock %}     
在Bookingformtype中创建Hiddenfield,如下所示:

public $bedroomid;
public function __construct($bedroomid = array())
{
        $this->bedroomid = $bedroomid;
}        
public function buildForm(FormBuilderInterface $builder, array $options) {
    $this->bedroomid = $options['empty_data'];
    $builder->add('booking', HiddenType::class, array(    
        'data'=> $this->bedroomid,
        'required' => false,
    ));
   }
试用控制器:

if ($form->isSubmitted() && $form->isValid()) {
       $bedroom = $form->getData()->getBedroom();
 }

现在,在submitt中,您可以获得卧室值…

为什么不使用VarDumper::dump($request)来查看您的请求是什么样子的?您可以提供您的操作的完整代码吗?@Stephan我可以在表单提交之前获得所需的值,但不能after@Anton我编辑了这本书post@Somesh谢谢男人:)为什么不使用VarDumper::dump($request)要查看您的请求是什么样子的?您能提供您的操作的完整代码吗?@Stephan我可以在提交表单之前获得所需的值,但不能after@Anton我编辑了这本书post@Somesh谢谢男人:)
public $bedroomid;
public function __construct($bedroomid = array())
{
        $this->bedroomid = $bedroomid;
}        
public function buildForm(FormBuilderInterface $builder, array $options) {
    $this->bedroomid = $options['empty_data'];
    $builder->add('booking', HiddenType::class, array(    
        'data'=> $this->bedroomid,
        'required' => false,
    ));
   }
if ($form->isSubmitted() && $form->isValid()) {
       $bedroom = $form->getData()->getBedroom();
 }