CodeIgniter Forums
Going back to a calling page - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Going back to a calling page (/thread-38531.html)

Pages: 1 2


Going back to a calling page - El Forum - 02-10-2011

[eluser]edjon2000[/eluser]
Hello again,

I am in the process of redesigning my ongoing web project to work with Reactor
and, have run into a few minor, but annoying problems, I say annoying because I am sure there is a workaround but for some reason I just can't see it, the first one is something that has been mentioned before and it relates to the URI PROTOCOL section of the CI config file and the fact that the AUTO option no longer seems to work, the reason I mention this is in case it is related to my second and main problem, I have a view page that can be called from various sections of the main site and I want to be able to link back to the calling page, in CI 1.7.3 I used code as follows
Code:
<?php echo anchor($_SERVER['HTTP_REFERER'], '« Back to previous page'); ?>
but this now generates an error message
Code:
A PHP Error was encountered

Severity: Notice

Message: Undefined index: HTTP_REFERER

Filename: site/views_view.php

Line Number: 9
on checking the $_SERVER super-global I noticed that there is no reference now to HTTP_REFERER

could this be related to the first problem I mantioned or is there some other solution that would work.

Any advice with this would be greatly appreciated

Jon


Going back to a calling page - El Forum - 02-10-2011

[eluser]Unknown[/eluser]
From the PHP Manual:
Quote:$_SERVER is an array containing information such as headers, paths, and script locations. The entries in this array are created by the web server. There is no guarantee that every web server will provide any of these; servers may omit some, or provide others not listed here.



Going back to a calling page - El Forum - 02-10-2011

[eluser]Jaketoolson[/eluser]
Personally, I've never created this 'functionality' nor have I used it. If I want to go back, I press back in my browser or press the button on my mouse that I've setup to send me back. I find these to be annoying actually just like the "Return to Top" anchors.

Code:
<a href="[removed] history.go(-1)">Back</a>



Going back to a calling page - El Forum - 02-11-2011

[eluser]LuckyFella73[/eluser]
What you could do is saving the called pages in a session and generate
a backlink via session values. That way you don't need javascript for that.
The URI helper would be useful here ( esp. "current_url()" or "uri_string()" ).

I would set up the "tracking" in an extended base controller to avoid repeating
the process of saving in every controller.


Going back to a calling page - El Forum - 02-11-2011

[eluser]edjon2000[/eluser]
Thank you for your responses.

@bellythroat
Thats a good point however both my development server(Zend CE) and my remote server(Linux-Apache) generate the HTTP_REFERER variable it has only "disappeared" since the change to Reactor, hence the reason I was thinking that it could be related to the URI PROTOCOL settings in the main config file for Reactor, in 1.7.3 it uses AUTO but that does not work correctly in Reactor yet.

@Jaketoolson
I find them annoying too, I always use the browser's back button, but, my client seems to think that the general users of his site would prefer to have the option, I have thought about using javascript but I find it very difficult language to pick up and understand, can you point out any useful tutorials about JS.

@LuckyFella73
As I am using database stored sessions anyway for the Admin section of the site I am thinking that perhaps this is the best option, I have read about setting up various extended features by extending the Base Controller but I am not sure how this actually works could you perhaps show me an example of what you mean

I appreciate all the help so far

Jon


Going back to a calling page - El Forum - 02-11-2011

[eluser]LuckyFella73[/eluser]
Phil Sturgeon wrote an article how to extend the base controller:
http://philsturgeon.co.uk/news/2010/02/CodeIgniter-Base-Classes-Keeping-it-DRY

Lets say you extented like shown in the articel and you have a Public_controller extending
the MY_Controller (extending the CI_Controller).
In your Public_controller you can set up some code that saves the pagelinks into
your session.
Code:
&lt;?php
class Public_Controller extends MY_Controller
{
    function __construct()
    {
        parent::__construct();
// here the code for saving ..
$last_url = = $foo_bar_code;
// ...

// them something like
$this->linktag_last_called_page = '<a href="'.$last_url.'">back to last page</a>';
}
}

Now you can set the link in all you view files like this without coding anything
in your "normal" controllers:
Code:
&lt;?php echo $this->linktag_last_called_page; ?&gt;



Going back to a calling page - El Forum - 02-11-2011

[eluser]edjon2000[/eluser]
Wow thanks LuckyFella73 for the quick response,
I will have a look at that article and try out the example above you kindly provided, although it seems that the change to Reactor seems to have removed a lot of the key functionality I liked in 1.7.3 in my case resulting in a non working project, it seems a bit strange that you now need to write additional code just to get back the functionality that has been removed, in fact my client said why not go back to 1.7.3 until the problems have been sorted out, although I did explain that it is better to stick with the more modern framework, my other alternative could be to use CI 2 Core rather than Reactor but I can't find a download link for that and can't see how to get the code from bitbucket (I can list the files but can't seem to download them, do I need to clone the entire repository) apparently CI 2 Core seems to work more reliably with projects that worked on 1.7.3, what are your thoughts on that.

Thanks again

Jon


Going back to a calling page - El Forum - 02-11-2011

[eluser]LuckyFella73[/eluser]
I'm glad if I could help you - hope everthing works like suggested Wink

For the donwlnload problem of CI 2 core - try this link:
https://bitbucket.org/ellislab/codeigniter

At the top right side you have a menu item "get source". There you can choose
between .zip , .gz and .bz2 packed versions.

But like bellythroat said - I don't think the $_SERVER['HTTP_REFERER'] problem
is a CI problem. I implemented this server-var in a CI project a while ago and
had the same problem when accessing the application with different browsers.

Hope you get your code to work


Going back to a calling page - El Forum - 02-11-2011

[eluser]edjon2000[/eluser]
Quote:For the donwlnload problem of CI 2 core - try this link:
https://bitbucket.org/ellislab/codeigniter

At the top right side you have a menu item “get source”. There you can choose
between .zip , .gz and .bz2 packed versions.
I can't believe I missed that

Quote:But like bellythroat said - I don’t think the $_SERVER[‘HTTP_REFERER’] problem
is a CI problem. I implemented this server-var in a CI project a while ago and
had the same problem when accessing the application with different browsers.
Both you and he are correct I have just gone back to my working copy of the 1.7.3 version of the project and the same error is being generated on both my local and remote dev versions so apologies to bellythroat and thanks for pointing out the situation I must have been using a different browser at the time or just plain missed the error


edit... I just had a look at Phil Sturgeons DRY example and it gave me a headache I think I will spend some time getting to understand how it works and implement that in my next project. I really want to get my current project finished and handed off so for now I will remove the backlinks and concentrate on finishing my database utility section for this project.

But I will implement everything you suggested in my next project(my own portfolio site)

Although I am used to general PHP/MySQL/Xhtml based web design, PHP frameworks in general are a new approach for me.

Jon


Going back to a calling page - El Forum - 02-11-2011

[eluser]WinkingFrog[/eluser]
I'll second the recommendation of Phil Sturgeon's article, I had been putting this extended setup off for a long time but realised a project I have on the go just now that it would massively simplify my controllers. It has!

It messed my nested views up a bit, but that was fixed with a template library.

Work through the headache and you will unlock even more power within CI! Wink