Welcome Guest, Not a member yet? Register   Sign In
[solved]Backspace key problem while surfing (new noob inside).

Hi people.

First of all, I apologize for my english. I'm a student of Computer Science and after learning a basic php and mysql, I'm trying to get my first Codeigniter web app working.

So, this is an example of my 'domain.com/home' controller/class called 'Home':

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Home extends CI_Controller {

  * Class Home
  * Main page of lesenpixel.com
public function __construct(){
     $data['content'] = 'home';
  $this->load->view('template', $data);
public function index(){

/* End of file home.php */
/* Location: ./application/controllers/home.php */

I've got another 3 like this one, for a navigation menu: Home - About - Services - Contact

The problem is while surfing arround by pressing the 'backspace' key instead of using the nav menu, I'm getting a 404 error. With the nav menu or refreshing the page works. But not with the 'backspace key'.

Any help will be appreciated.


I don't know why but the problem (404) while surfing solves if i do this:

Just one controller named 'Site' with functions for each nav menu:
public function home(){

  $data['content'] = 'home_content';
  $this->load->view('template', $data);

public function about(){

  $data['content'] = 'about_content';
  $this->load->view('template', $data);
public function contact(){

  $data['content'] = 'contact_content';
  $this->load->view('template', $data);

But i dislike the URL access -> myweb.com/site/home

┬┐Is it possible to access more directly? like 'web.com/home' instead of 'web.com/site/home'


Try this:
$route['home'] = "site/about";

Thanks for your reply.

That's a good idea and solves the URL access I've posted in #1...

but still gets the 404 error when doing this:

1- web.com/about ---> OK, shows the content in web.com/site/about
2- web.com/contact ---> OK, shows the content in web.com/site/contact
3- I wank to go back with 'backspace key' or the 'back button of the browser' and it crashes ->> PROBLEM! 404 error : page not found.

I feel like an idiot.

You can not control the browser back button maybe using jQuery but not PHP.

The browser back button keeps the history.

From the sounds of it you are using the wrong type of menu! You should be using a css or jQuery menu system.

You did not show your code for the menu view so it's hard to figure out what your doing...

I make a guess. Maybe it depends by the interaction between the browser cache (called by the back button) and CI: you have put your page view not inside a method but into the constructor itself, this means that the page view will be rendered only if the server parses a new request (as in direct requests or clicking on menu items) but not after a call from the browser cache, which will check if the page has been modified before calling again the server. With no modified flag, CI maybe does not run again the constructor but will try and render only the content of the index() method (called by the default routing) which is empty and therefore gives no result. That would explain also because everything works well also with back button when you put the views inside methods and not into the constructor.
But I am not sure about this behavior, I am guessing.
Try moving the view from the the constructor into the index method and check if this solve the problem.

Thanks for your replies.

InsiteFX, yes, I've got a menu based in html/css... I mean:

a href = "/site/home" title="Main page">Home</a>

I use this structure:
// Class Site, controller
public function home(){
        $data['content'] = 'home_content';
$this->load->view('template', $data);  

// home_content.php (view with the content of home)

<div>My content blah blah blah</div>

// template.php (it's a view)






// In my view: 'includes/header.php' should be the nav. menu
a href="/site/home">Home</a>

So, can you please point to me the idea or some examples to make a 'codeignite navigation menu' and how to show it?

Try using CodeIgniters anchor tag

CodeIgniter User Guide - URL Helper

Thanks for your help InsiteFX.

Finally it was a browser problem. After quite browser's restart, cleaning cookies etc. It solves.

So guys, thanks for your interest and help.

Theme © iAndrew 2016 - Forum software by © MyBB