Welcome Guest, Not a member yet? Register   Sign In
Anchor links do not work
#1

[eluser]variouspixels[/eluser]
can anyone help me? If I go to http://localhost/index.php/site/index or http://localhost/ I can see my homepage as expected. I set the following on relevant page.
Code:
$config['index_page'] = "";
$route['default_controller'] = "site";
.

The problem:

http://localhost/about does not work
My anchor links in header_view.php do not work either.
Code:
<?= anchor('/about', 'About', array('title' => 'About')); ?>



My code:


Code:
class Site extends Controller {

    function index() {
    
    $data = array();
        $data['title'] = 'Home';
        $this->load->view('header_view', $data);
        $data = array();
        $this->load->view('home_view', $data);
        $data = array();
        $this->load->view('footer_view', $data);
    }

function about() {
    
    $data = array();
        $data['title'] = 'About';
        $this->load->view('header_view', $data);
        $data = array();
        $this->load->view('home_view', $data);
        $data = array();
        $this->load->view('footer_view', $data);
    }
}

Hope this make sense. Noob here.

many thanks
#2

[eluser]mddd[/eluser]
If you request /about, that means you are looking for the controller called About. That is not the case, you need the controller called Site and the METHOD called about. So that would be /site/about.

If you want /about to refer to this, you could make a rule that says
Code:
$route['about'] = 'site/about';

What you need to realize, is that the 'default controller' route will only work if there is no controller requested. That means: if the user asks for '/'. THEN the default controller kicks in. But if you give a url, the default controller does not activate.
#3

[eluser]steelaz[/eluser]
Did you setup your .htaccess file (http://ellislab.com/codeigniter/user-guide/general/urls.html)? Are you testing on Linux or Windows system?
#4

[eluser]variouspixels[/eluser]
@mddd I have changed the link to site/about but still no change.
@steelaz I am using MAMP locally atm. I have not added a .htaccess file. I will try find the correct rule to fix my problem.

thanks
#5

[eluser]flaky[/eluser]
Code:
http://localhost/about
doesn't work because there is no controller with the name about, instead use
Code:
http://localhost/index.php/site/about
same for the anchor link
Code:
<?= anchor('site/about', 'About', array('title' => 'About')); ?>
#6

[eluser]Ivar89[/eluser]
If you don't have a htaccess file you need index.php
so; http://localhost/index.php/about
#7

[eluser]variouspixels[/eluser]
@ivar89 links are working fine now I have set
Code:
$config['index_page'] = "index.php";
.

I will need to remove the index.php/site from the url though. I guess I use .htaccess instead of changing any codeigniter parameters.
#8

[eluser]variouspixels[/eluser]
Removed index.php succesfully by adding relevant htaccess file.

Enabled http://localhost/about and http://localhost/contacts pages to work correctly by following advice from mddd.

However, my CSS files no longer work and I cannot figure out why. Any ideas?
#9

[eluser]steelaz[/eluser]
It's possible that you configured .htaccess file incorrectly. Can you open your css file by entering url in a browser?
#10

[eluser]variouspixels[/eluser]
No I cannot. 404

.htaccess
Code:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]




Theme © iAndrew 2016 - Forum software by © MyBB