Redirect to History – Yii


Yii is an open source, object-oriented, component-based MVC PHP web application framework. Yii is pronounced as “Yee” and in Chinese it means “simple and evolutionary”

Yii is the one of major MVC framework of PHP. We need to redirect the previous / history page for some circumstances in every development.

Here we show how to achieve that;

If you want to get previous URL use below line of code

If you want to redirect to the previous URL use below line of code

 To redirect to absolute URL with json response

Following code should work for you:

You have to build your http query by your own. Yii does not support any function that helps you to create outbound urls with query parameters.

READ  PHP PSR Auto Formatting Tool

In controller, use:

If you want redirect to action:

To ensure route is working, you have to pass array to CController::redirect():

In other case you will have redirect broken on url rules change.

READ  Magento - From Beginner to Advanced