Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This is the way I save a request and use it later to redirect to the correct action.</p> <p><strong>1) Unauthorized action saves the request with all GET/POST params.</strong></p> <pre><code>$session = new Container('base'); $session-&gt;offsetSet("lastRequest", $event-&gt;getRequest()); </code></pre> <p><strong>2) After success login, redirect to requested</strong></p> <pre><code>$session = new Container('base'); if($lastRequest = $session-&gt;offsetGet("lastRequest")) { //Just redirect, because I could NOT find a way to POST params return $this-&gt;redirect()-&gt;toUrl($lastRequest-&gt;getRequestUri()); } </code></pre> <p><strong>3) Before controller action, retrieve all POST/GET params</strong></p> <pre><code>class Module { //... public function init($moduleManager) { $sharedEvents = $moduleManager-&gt;getEventManager()-&gt;getSharedManager(); $sharedEvents-&gt;attach(__NAMESPACE__, \Zend\Mvc\MvcEvent::EVENT_DISPATCH, array($this, 'preDispatch'), 100); } public function preDispatch($event) { //Unauthorized request after success login $session = new Container('base'); if($lastRequest = $session-&gt;offsetGet("lastRequest")) { $event-&gt;getTarget()-&gt;getRequest()-&gt;setMethod($lastRequest-&gt;getMethod()); $event-&gt;getTarget()-&gt;getRequest()-&gt;setPost($lastRequest-&gt;getPost()); $event-&gt;getTarget()-&gt;getRequest()-&gt;setQuery($lastRequest-&gt;getQuery()); //Delete request $session-&gt;offsetSet("lastRequest", null); } } </code></pre> <p><strong>4) Just use the request on any destination action as normal</strong></p> <pre><code>class ManageController extends AbstractActionController { public function createAction() { if ($this-&gt;getRequest()-&gt;isPost()) { $post = $this-&gt;getRequest()-&gt;getPost()-&gt;toArray(); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload