Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create back link user referer in CakePHP

Tags:

php

cakephp

I've tried doing the following in my 404 error page to create a back link the referring page so that I don't have to rely on javascript.

<?php $this->set('refer', $this->referer()); ?>

<p><?php echo '<a href="'.$refer.'">Back to previous page</a>'; ?></p>

However it doesn't work... Any ideas why? This code is done in /Errors/error404.ctp

like image 522
Cameron Avatar asked Jun 01 '12 14:06

Cameron


2 Answers

Use the request object :)

$this->request->referer();
like image 130
Hippie Avatar answered Oct 30 '22 15:10

Hippie


In CakePHP3 you can use:

<li><?= $this->Html->link(__('Back'), $this->request->referer()) ?></li>

It should be fine.

like image 33
Xavier Carreón Avatar answered Oct 30 '22 15:10

Xavier Carreón