When a user hits submit button in a webform (for instance, to insert data into database) event listener treats it as Master POST request whcih is fine. After successfull submission (data inserted into db), the logic return $this->redirect($this->generateUrl('home'));
we have written in controller redirects user to success or fail page and this is also treated as Master GET request. Is it not supposed to be Sub GET request instead because user doesn't directly cause it?
Either I get whole stuff wrong or the answers (what is the difference between MASTER / SUB REQUEST in Symfony2?) here are short/wrong.
And full Doc is here.
The reason I'm asking is I want to avoid allocating system resources when redirect
happens.
SERVICE:
services:
kernel.listener.kernel_request:
class: Site\MainBundle\EventListener\Request\KernelRequest
tags:
- { name: kernel.event_listener, event: kernel.request, method: onKernelRequest }
EVENT LISTENER CLASS:
<?php
namespace Site\MainBundle\EventListener\Request;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
class KernelRequest
{
public function onKernelRequest(GetResponseEvent $event)
{
if ($event->isMasterRequest() === true) {
// Do something with Master request
} else {
// Do something with sub request
}
}
}
CIONTROLLER:
publich function saveAction()
{
// Insert user's POST stuff into database
// Then either redirect to success or fail page like;
return $this->redirect($this->generateUrl('success-or-fail-page'));
}