PHP code example of basster / lazy-response-bundle
1. Go to this page and download the library: Download basster/lazy-response-bundle library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
basster / lazy-response-bundle example snippets
use Basster\LazyResponseBundle\Response\LazyResponseInterface;
use Basster\LazyResponseBundle\Response\RedirectResponse;
use Basster\LazyResponseBundle\Response\TemplateResponse;
class MyController {
public function commentNew(Request $request, FormFactoryInterface $formFactory): LazyResponseInterface
{
$post = new Post();
$form = $formFactory->create(PostType::class, $post);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
// do stuff with the submitted data
return new RedirectResponse('post_index'); // will end up in a RedirectResponse
}
return new TemplateResponse('post/new.html.twig',[
'post' => $post,
'form' => $form->createView(),
]); // will end up in a regular Response with contents of the rendered template.
}
}