Welcome Guest

Zend Framework 2 & 3 / Laminas Refresh Redirect Module

I was inspired to write this simple module after using ZF flashMessenger controller plugin and view helper. The problem I found is when using the view helper the messages in flashMessenger are deleted, this means that if the user refreshes the page all messages are gone. This can possibly lead to errors depending on your code. To overcome this issue I wrote the refresh redirect module, this simply checks if the same page is called a second time, if so redirect to a different page.

Installation

With composer
  1. In the root of your application enter:
    $ composer require krytenuk/refresh-redirect
Post installation
  1. Enable it in your `application.config.php` or `modules.config.php` file.
    For ZF2 edit your `application.config.php` file.
    <?php
        
    return array(
            
    'modules' => array(
                
    // ...
                
    'FwsRefreshRedirect',
            ),
            
    // ...
        
    );

    For ZF3/Laminas edit your `modules.config.php` file.
    <?php
        
    return [
            
    'FwsRefreshRedirect',
            
    // ...
        
    ];

Usage

Refresh Redirect is a controller plugin, when added to your controller actions, a page refresh will redirect to the specified route or url.

Redirect to route

To redirect to a route use: <?php
    $route 
'your/route';
    
$params = array(); // your route params (optional)
    
$options = array(); // your route options (optional)
    
$reuseMatchedParams FALSE// reuse matched parameters (optional)
    
$this->refreshRedirect($route$params$options$reuseMatchedParams);
    
// or use
    
$this->refreshRedirect()->toRoute($route$params$options$reuseMatchedParams);

Redirect to url

To redirect to a url use: <?php
    $url 
'https://www.yourdomain.com';
    
$this->refreshRedirect()->toUrl($url);

See Laminas Framework redirect plugin for more info on the redirect parameters.

Donate