PHP code example of vkr / controller-delegation-bundle

1. Go to this page and download the library: Download vkr/controller-delegation-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/ */

    

vkr / controller-delegation-bundle example snippets

$this->controller
$this->delegateResponse

public function myDelegatedAction($someArgument)
{
    ...
    $viewData = [
        'templateVar' => 'value',
    ];
    return $this->delegateResponse->setViewData($viewData);
}

$this->delegateResponse->setViewData($viewData);
return $this->delegateResponse;

public function myDelegatedAction($someArgument)
{
    $delegate = new MyDelegate($this);
    $delegateResponse = $delegate->myDelegatedAction($someArgument);
    $parsedResponse = $this->parseDelegateResponse($delegateResponse);
    return $this->render('my/template.html.twig', $parsedResponse);
}

return $this->delegateResponse->setRouteToRedirect($this->redirectRoutes['success']);

$redirectRoutes = ['success' => 'my_success_route'];
$delegate = new MyDelegate($this, $redirectRoutes);
...
return $this->parseDelegateResponse($delegateResponse);

$parsedResponse = $this->parseDelegateResponse($delegateResponse);
if ($parsedResponse instanceof RedirectResponse) {
    return $parsedResponse;
}
return $this->render('my/template.html.twig', $parsedResponse);

#Delegate
return $this->delegateResponse->setUrlToRedirect('https://api.facebook.com');

#Controller
public function sendEmailAction()
{
    $emailData = [
        'subject' => 'My subject',
        'template' => 'my/email/template.html.twig',
        'templateVars' => [
            'foo' => 'bar'
        ],
    ];
    $delegate = new RegistrationDelegate($this);
    $delegateResponse = $delegate->myDelegatedAction($emailData);
}

$this->controller->render($emailData['template'], $emailData['templateVars']);