{"id":15672902,"url":"https://github.com/cornernote/yii2-returnurl","last_synced_at":"2025-10-20T06:51:47.162Z","repository":{"id":32832714,"uuid":"36425855","full_name":"cornernote/yii2-returnurl","owner":"cornernote","description":"ReturnUrl helper for tab-aware nested redirection in Yii2","archived":false,"fork":false,"pushed_at":"2023-08-15T04:21:46.000Z","size":48,"stargazers_count":14,"open_issues_count":1,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-05-06T22:05:46.476Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cornernote.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-05-28T08:44:22.000Z","updated_at":"2024-12-11T19:55:36.000Z","dependencies_parsed_at":"2024-10-23T11:02:31.677Z","dependency_job_id":"486627f2-abdd-402e-a896-d0a3d8a3a43b","html_url":"https://github.com/cornernote/yii2-returnurl","commit_stats":{"total_commits":46,"total_committers":2,"mean_commits":23.0,"dds":"0.021739130434782594","last_synced_commit":"bcf9f47053ab9ad2825def8ee50e3aee3c72c4b6"},"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cornernote%2Fyii2-returnurl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cornernote%2Fyii2-returnurl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cornernote%2Fyii2-returnurl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cornernote%2Fyii2-returnurl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cornernote","download_url":"https://codeload.github.com/cornernote/yii2-returnurl/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252776579,"owners_count":21802468,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-03T15:33:22.811Z","updated_at":"2025-10-20T06:51:42.121Z","avatar_url":"https://github.com/cornernote.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Yii2 ReturnUrl\n\n[![Latest Version](https://img.shields.io/github/tag/cornernote/yii2-returnurl.svg?style=flat-square\u0026label=release)](https://github.com/cornernote/yii2-returnurl/tags)\n[![Software License](https://img.shields.io/badge/license-BSD-brightgreen.svg?style=flat-square)](LICENSE.md)\n[![Build Status](https://img.shields.io/travis/cornernote/yii2-returnurl/master.svg?style=flat-square)](https://travis-ci.org/cornernote/yii2-returnurl)\n[![Coverage Status](https://img.shields.io/scrutinizer/coverage/g/cornernote/yii2-returnurl.svg?style=flat-square)](https://scrutinizer-ci.com/g/cornernote/yii2-returnurl/code-structure)\n[![Quality Score](https://img.shields.io/scrutinizer/g/cornernote/yii2-returnurl.svg?style=flat-square)](https://scrutinizer-ci.com/g/cornernote/yii2-returnurl)\n[![Total Downloads](https://img.shields.io/packagist/dt/cornernote/yii2-returnurl.svg?style=flat-square)](https://packagist.org/packages/cornernote/yii2-returnurl)\n\nReturnUrl helper for tab-aware nested redirection in Yii2.\n\nYou might be saying, Yii2 already handles a returnUrl perfectly fine with the `Url::remember()` and `Url::previous()` methods.  Why not use those?\n\nThese 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:\n\n- A user navigates to a page that sets a returnUrl.  The page is for a form they have to complete.\n- The phone rings, and they are required to fill in a different form.  They achieve this by opening another tab.\n- 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.\n- They then return to their first form, and after submission they get taken to the second returnUrl and their navigation path appears broken.\n\nThe 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.\n\n\n## Features\n\n- Allows a URL to be consistent with the page the user is viewing, even if they open other tabs.\n- Easily embed return URLs into your links or forms.\n- Handles very long returnUrl values by passing a token in the GET/POST request data.\n\n\n## Requirements\n\nReturnUrl uses cache to store URL to Token mapping.  Due to this you must have a cache component in your config, for example:\n\n```\n$config = [\n    'components' =\u003e [\n        'cache' =\u003e [\n           'class' =\u003e 'yii\\caching\\FileCache',\n        ],\n    ],\n],\n```\n\n\n## Installation\n\nThe preferred way to install this extension is through [composer](http://getcomposer.org/download/).\n\nEither run\n\n```\n$ composer require cornernote/yii2-returnurl \"*\"\n```\n\nor add\n\n```\n\"cornernote/yii2-returnurl\": \"*\"\n```\n\nto the `require` section of your `composer.json` file.\n\n\n## Methods\n\n`ReturnUrl::getToken()` - Creates and returns a new token.  Pass this into the request to mark the current page as the origin url.\n\n`ReturnUrl::getRequestToken()` - Returns the current token.  Pass this into the request to allow multiple pages to be visited before returning to the origin url.\n\n`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.\n\n\n## Usage\n\nYour 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.\n\nOn 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`:\n```php\n// generate a returnUrl link value\nHtml::a('edit post', ['post/update', 'id' =\u003e $post-\u003eid, 'ru' =\u003e ReturnUrl::getToken()]);\n```\n\nOn 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`:\n```php\n// generate a returnUrl form value\nHtml::hiddenInput('ru', ReturnUrl::getRequestToken());\n```\n\nIn the controller action that handles the form, change the call to `$this-\u003eredirect($url)` to `$this-\u003eredirect(ReturnUrl::getUrl($url))`.  This redirects the user to the origin url.  For example in `Post::actionUpdate()`\n```php\n// this is where we used to redirect to, we use it as a fail-back\n// (if not provided then we redirect to the home page)\n$altUrl = ['post/index'];\nreturn $this-\u003eredirect(ReturnUrl::getUrl($altUrl));\n```\n\n## Examples\n\n![list](https://cloud.githubusercontent.com/assets/51875/8023635/1a1e89ba-0d53-11e5-9a1d-0f7edb45a97c.png)\n![update](https://cloud.githubusercontent.com/assets/51875/8023636/1bd293c8-0d53-11e5-94c3-66fba15eff96.png)\n![relations](https://cloud.githubusercontent.com/assets/51875/8023634/19eb5e50-0d53-11e5-9d3c-72cc19b06c53.png)\n\n\n## License\n\n- Author: Brett O'Donnell \u003ccornernote@gmail.com\u003e\n- Source Code: https://github.com/cornernote/yii2-return-url\n- Copyright © 2015 Mr PHP \u003cinfo@mrphp.com.au\u003e\n- License: BSD-3-Clause https://raw.github.com/cornernote/yii2-return-url/master/LICENSE\n\n\n## Links\n\n- [Yii2 Extension](http://www.yiiframework.com/extension/yii2-return-url)\n- [Composer Package](https://packagist.org/packages/cornernote/yii2-return-url)\n- [MrPHP](http://mrphp.com.au)\n\n\n[![Mr PHP](https://raw.github.com/cornernote/mrphp-assets/master/img/code-banner.png)](http://mrphp.com.au) \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcornernote%2Fyii2-returnurl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcornernote%2Fyii2-returnurl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcornernote%2Fyii2-returnurl/lists"}