PHPackages                             cornernote/yii2-returnurl - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. cornernote/yii2-returnurl

ActiveYii2-extension[Utility &amp; Helpers](/categories/utility)

cornernote/yii2-returnurl
=========================

ReturnUrl helper for tab-aware nested redirection in Yii2.

1.0.2(9y ago)145.9k↓25.6%2[1 PRs](https://github.com/cornernote/yii2-returnurl/pulls)1BSD-3-ClausePHP

Since Jun 20Pushed 2y ago3 watchersCompare

[ Source](https://github.com/cornernote/yii2-returnurl)[ Packagist](https://packagist.org/packages/cornernote/yii2-returnurl)[ RSS](/packages/cornernote-yii2-returnurl/feed)WikiDiscussions master Synced today

READMEChangelog (3)Dependencies (3)Versions (4)Used By (1)

Yii2 ReturnUrl
==============

[](#yii2-returnurl)

[![Latest Version](https://camo.githubusercontent.com/5d56e9af29a220e90b970d760263fed505e3e6e01992faa7314dc7f55c9278bb/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f7461672f636f726e65726e6f74652f796969322d72657475726e75726c2e7376673f7374796c653d666c61742d737175617265266c6162656c3d72656c65617365)](https://github.com/cornernote/yii2-returnurl/tags)[![Software License](https://camo.githubusercontent.com/b60331a2084501dc07cf6d6964c0da58dd005d89c45cf3b28b4b22b60f5ec00f/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4253442d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/952cd517340c558b712231c7b7fd382eae9fc9f3a2da8aa9bace214869c70b7a/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f636f726e65726e6f74652f796969322d72657475726e75726c2f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/cornernote/yii2-returnurl)[![Coverage Status](https://camo.githubusercontent.com/8eb98d222e92e2a9f5eaf7570d8bf8cefb1908795a906fbe35b807d9265dc9e6/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f636f726e65726e6f74652f796969322d72657475726e75726c2e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/cornernote/yii2-returnurl/code-structure)[![Quality Score](https://camo.githubusercontent.com/8d942ad20969ef5a0d9303a607fd8364320dca7be4a438c91141966e3adf2554/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f636f726e65726e6f74652f796969322d72657475726e75726c2e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/cornernote/yii2-returnurl)[![Total Downloads](https://camo.githubusercontent.com/a0d98a383bb22a20ac07eab13731280726c5afb3915f8e0afe17541886637073/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f636f726e65726e6f74652f796969322d72657475726e75726c2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/cornernote/yii2-returnurl)

ReturnUrl helper for tab-aware nested redirection in Yii2.

You might be saying, Yii2 already handles a returnUrl perfectly fine with the `Url::remember()` and `Url::previous()` methods. Why not use those?

These methods store the returnUrl into a single variable in the users session. This becomes a flaw when we have multiple tabs open. Take the following scenario:

- A user navigates to a page that sets a returnUrl. The page is for a form they have to complete.
- The phone rings, and they are required to fill in a different form. They achieve this by opening another tab.
- As they navigate to the new page, their old returnUrl is overwritten by the new one, they complete the second form and everything seems normal.
- They then return to their first form, and after submission they get taken to the second returnUrl and their navigation path appears broken.

The solution is to pass the returnUrl into the GET and POST request by embedding it into your links and forms. This extension makes it very easy to do and solves many common problems including the maximum length of a GET request.

Features
--------

[](#features)

- Allows a URL to be consistent with the page the user is viewing, even if they open other tabs.
- Easily embed return URLs into your links or forms.
- Handles very long returnUrl values by passing a token in the GET/POST request data.

Requirements
------------

[](#requirements)

ReturnUrl uses cache to store URL to Token mapping. Due to this you must have a cache component in your config, for example:

```
$config = [
    'components' => [
        'cache' => [
           'class' => 'yii\caching\FileCache',
        ],
    ],
],

```

Installation
------------

[](#installation)

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

Either run

```
$ composer require cornernote/yii2-returnurl "*"

```

or add

```
"cornernote/yii2-returnurl": "*"

```

to the `require` section of your `composer.json` file.

Methods
-------

[](#methods)

`ReturnUrl::getToken()` - Creates and returns a new token. Pass this into the request to mark the current page as the origin url.

`ReturnUrl::getRequestToken()` - Returns the current token. Pass this into the request to allow multiple pages to be visited before returning to the origin url.

`ReturnUrl::getUrl($altUrl)` - Return the origin url or `$altUrl` if no token was found in the request data. Use this value to redirect to the origin url.

Usage
-----

[](#usage)

Your user is on a search results page, and you have a link to an update form. After filling in the form you want the user to be returned to the page they started from.

On the start page, add a `ReturnUrl::getToken()` to your link. This will set the current page as the origin url. For example in `views/post/index.php`:

```
// generate a returnUrl link value
Html::a('edit post', ['post/update', 'id' => $post->id, 'ru' => ReturnUrl::getToken()]);
```

On the update page, add a `ReturnUrl::getRequestToken()` to your form. This will pass the existing token through to the next page so that the controller can redirect to the origin url after it successfully saves. For example in `views/post/update.php`:

```
// generate a returnUrl form value
Html::hiddenInput('ru', ReturnUrl::getRequestToken());
```

In the controller action that handles the form, change the call to `$this->redirect($url)` to `$this->redirect(ReturnUrl::getUrl($url))`. This redirects the user to the origin url. For example in `Post::actionUpdate()`

```
// this is where we used to redirect to, we use it as a fail-back
// (if not provided then we redirect to the home page)
$altUrl = ['post/index'];
return $this->redirect(ReturnUrl::getUrl($altUrl));
```

Examples
--------

[](#examples)

[![list](https://cloud.githubusercontent.com/assets/51875/8023635/1a1e89ba-0d53-11e5-9a1d-0f7edb45a97c.png)](https://cloud.githubusercontent.com/assets/51875/8023635/1a1e89ba-0d53-11e5-9a1d-0f7edb45a97c.png)[![update](https://cloud.githubusercontent.com/assets/51875/8023636/1bd293c8-0d53-11e5-94c3-66fba15eff96.png)](https://cloud.githubusercontent.com/assets/51875/8023636/1bd293c8-0d53-11e5-94c3-66fba15eff96.png)[![relations](https://cloud.githubusercontent.com/assets/51875/8023634/19eb5e50-0d53-11e5-9d3c-72cc19b06c53.png)](https://cloud.githubusercontent.com/assets/51875/8023634/19eb5e50-0d53-11e5-9d3c-72cc19b06c53.png)

License
-------

[](#license)

- Author: Brett O'Donnell
- Source Code:
- Copyright © 2015 Mr PHP
- License: BSD-3-Clause

Links
-----

[](#links)

- [Yii2 Extension](http://www.yiiframework.com/extension/yii2-return-url)
- [Composer Package](https://packagist.org/packages/cornernote/yii2-return-url)
- [MrPHP](http://mrphp.com.au)

[![Mr PHP](https://camo.githubusercontent.com/5c2a4e06b8343bc0132af3775a46e3cbe9b40f69708f11bf40869fc560fdde17/68747470733a2f2f7261772e6769746875622e636f6d2f636f726e65726e6f74652f6d727068702d6173736574732f6d61737465722f696d672f636f64652d62616e6e65722e706e67)](http://mrphp.com.au)

###  Health Score

36

—

LowBetter than 79% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity30

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor1

Top contributor holds 97.9% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~344 days

Total

3

Last Release

3342d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/07c84a589344489e8195ec1c6afcfa3abcc23a73092ceaa4ca60da96355c4d16?d=identicon)[cornernote](/maintainers/cornernote)

---

Top Contributors

[![cornernote](https://avatars.githubusercontent.com/u/51875?v=4)](https://github.com/cornernote "cornernote (46 commits)")[![uldisn](https://avatars.githubusercontent.com/u/3525344?v=4)](https://github.com/uldisn "uldisn (1 commits)")

---

Tags

urlyii2returnUrl

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/cornernote-yii2-returnurl/health.svg)

```
[![Health](https://phpackages.com/badges/cornernote-yii2-returnurl/health.svg)](https://phpackages.com/packages/cornernote-yii2-returnurl)
```

###  Alternatives

[craftcms/cms

Craft CMS

3.6k3.6M3.1k](/packages/craftcms-cms)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
