Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How send anchor to URL with render() Yii [closed]

Tags:

html

anchor

yii

Hi i wont render view with anchor location - http://example.com/index.php#top

may be like this:

$this->render('index', ['data' => $data], 'anchor'=>'top');

Any ideas?

like image 468
Ilya Vo Avatar asked Oct 26 '25 11:10

Ilya Vo


1 Answers

When you call render the url is already set because you are in the controller (or the view). So you can't add an anchor to the url at this time.

You must set the anchor before the controller is called.To do it you can set an anchor when you create the url:

$this->createUrl('controller/action', array('#' => 'the-anchor'));

You could also use redirect to redirect the visitor to the page with the anchor

$this->redirect(array('controller/action', array('#' => 'the-anchor')));

but I think that set the anchor when you create the url is the best way to achieve what you want.

like image 181
darkheir Avatar answered Oct 28 '25 04:10

darkheir



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!