J
J
john_ricko2016-11-19 22:29:28
Yii
john_ricko, 2016-11-19 22:29:28

Yii2 how to redirect to referrer with anchor?

Hello.
The problem is the following, there is a page with the order of the goods, where it is placed in the basket.
That is, first the action of adding a product to the cart is performed, and then a redirect to the previous page, but with an anchor to the list of products, so as not to scroll down again.

return $this->redirect([yii::$app->request->referrer,'#' => 'grid']);

This code works, but inserts an absolute link and therefore throws a 404 because adds to the controller address.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
J
john_ricko, 2016-11-20
@john_ricko

I tried several ways, but so far I had to do this -

$this->registerJs('window.onload = function() {
    location.hash = \'#grid\';
}');

When loading the page, Javascript itself translates to the desired anchor.

D
Dmitry, 2016-11-19
@slo_nik

Good evening.

<?php
// создает якорный URL: /index.php?r=post/view&id=100#content
echo Url::to(['post/view', 'id' => 100, '#' => 'content']);
?>

Read more here

S
samizdam, 2016-11-19
@samizdam

www.yiiframework.com/doc-2.0/yii-web-controller.ht...
Have you read it?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question