A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://docs.zendframework.com/zend-mvc-plugin-prg/ below:

mvc-plugin-prg - Zend Framework Docs

  1. Home
  2. Documentation
  3. zend-mvc-plugin-prg
zend-mvc-plugin-prg

Post/Redirect/Get plugin for zend-mvc controllers

Installation

Install via composer:

$ composer require zendframework/zend-mvc-plugin-prg

If you are using the zend-component-installer, you're done!

If not, you will need to add the component as a module to your application. Add the entry 'Zend\Mvc\Plugin\Prg' to your list of modules in your application configuration (typically one of config/application.config.php or config/modules.config.php).

Usage

When a user sends a POST request (e.g. after submitting a form), their browser will try to protect them from sending the POST again, breaking the back button, causing browser warnings and pop-ups, and sometimes reposting the form. Instead, when receiving a POST, we should store the data in a session container and redirect the user to a GET request.

This plugin can be invoked with two arguments:

When no arguments are provided, the current matched route is used.

Example Usage
// Pass in the route/url you want to redirect to after the POST
$prg = $this->prg('/user/register', true);

if ($prg instanceof \Zend\Http\PhpEnvironment\Response) {
    // Returned a response to redirect us.
    return $prg;
}

if ($prg === false) {
    // This wasn't a POST request, but there were no params in the flash
    // messenger; this is probably the first time the form was loaded.
    return ['form' => $myForm];
}

// $prg is an array containing the POST params from the previous request
$form->setData($prg);

// ... your form processing code here
Support

Found a mistake or want to contribute to the documentation? Edit this page on GitHub!


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4