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

[eluser]Asshai[/eluser]
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':

Code:
<?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(){
        
     parent::__construct();
    
     session_start();
     $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.

Cheers.
#2

[eluser]Asshai[/eluser]
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:
Code:
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'

Cheers.
#3

[eluser]InsiteFX[/eluser]
Try this:
./application/config/routes.php
Code:
$route['home'] = "site/about";
#4

[eluser]Asshai[/eluser]
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.
#5

[eluser]InsiteFX[/eluser]
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...
#6

[eluser]@robertotra[/eluser]
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.
Roberto
#7

[eluser]Asshai[/eluser]
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:
Code:
// 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)

&lt;?php

$this->load->view('includes/header');

$this->load->view($content);

$this->load->view('includes/footer');

?&gt;

// 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?
#8

[eluser]InsiteFX[/eluser]
Try using CodeIgniters anchor tag

CodeIgniter User Guide - URL Helper
#9

[eluser]Asshai[/eluser]
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