This website uses cookies to help us give you the best experience when you visit our website. By continuing to use this website, you consent to our use of these cookies.

Find out more about how we use cookies and how to manage them by reading our Privacy Policy

Close

Zend Framework 2 Refresh Redirect Module

I was inspired to write this simple module after using ZF flashMessanger controller plugin and view helper. The problem I found is when using the view helper the messages in flashMessanger 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

By cloning project
  1. Install the [FwsRefreshRedirect](https://github.com/krytenuk/refreshRedirect) ZF2 module by cloning it into `./vendor/`.
  2. Clone this project into your `./vendor/` directory.
With composer
  1. Add this project in your composer.json:
    "require": {
        "krytenuk/refresh-redirect": "1.0.*"
    }
  2. Now tell composer to download FwsRefreshRedirect by running the command:
    $ php composer.phar update
Post installation
  1. Enabling it in your `application.config.php` file.
    <?php
        
    return array(
            
    'modules' => array(
                
    // ...
                
    '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 
'http://www.yourdomain.com';
    
$this->refreshRedirect->toUrl($url);

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