I want to check condition on previous action name. I got the previous action url from Yii::$app->request->referrer
.
Now i want to parse only action name Or there is another way to directly get referer action name.
You can easily parse the URL by mocking a Request
object and passing it to the UrlManger
.
Imagine we have URL http://example.com/user/42
, and UrlManager
has the following rule: ['user/<id:\d+>' => 'user/view']
$request = new Request(['url' => parse_url(Yii::$app->request->referrer, PHP_URL_PATH)]);
$url = Yii::$app->urlManager->parseRequest($request);
var_dump($url); // ['user/view', 'id' => 42]
Cool, isn't it? :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With