Welcome Guest, Not a member yet? Register   Sign In
Basic newbie question regarding navigation links
#1

[eluser]sehummel[/eluser]
I'm brand new to CI and have a very basic question. As I recall from my previous limited experience with CI, to refer to a controller in the navigation, we put <a href="controller_name"> rather than adding the PHP extension to it. But yet I get a 404 error when I do this. I know my second controller works because I can load it as the default controller and it loads my view.

What am I doing wrong? The controller is in my root controllers folder
#2

[eluser]Madmartigan1[/eluser]
You may not have .htaccess configured, or your CI config.

Try

http://your_website.com/index.php/controller_name

and see what happens.

Read the manual as well. Then read it again. It sounds like you may have other issues as far as understanding how CI works.
#3

[eluser]sehummel[/eluser]
Thanks. Yeah, I guess I should have RTFD.
#4

[eluser]Bart v B[/eluser]
Some code woul be nice.
But i am guessing that you forgot to change some config things.. Wink
So when you go to <a href="index.php/controller_name"> then it should be right.

To remove the index.php you can do that to open config/config.php and change the folow settings:
Code:
&lt;?php
$config['base_url']    = "http://example.com/"; // change to youre domainname..

$config['index_page'] = "index.php"; // remove index.php
?&gt;

What i always do is using the base_url()
The it works alway's correct.
example:
Code:
<a href="&lt;?php echo base_url();?&gt;controller_name/">something</a>
#5

[eluser]Madmartigan1[/eluser]
A little copy/paste from the maunal that may help:

Quote:By default, the index.php file will be included in your URLs:
example.com/index.php/news/article/my_article

You can easily remove this file by using a .htaccess file with some simple rules. Here is an example of such a file, using the "negative" method in which everything is redirected except the specified items:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]

In the above example, any HTTP request other than those for index.php, images, and robots.txt is treated as a request for your index.php file.

And yes, definitely use full urls if you have issues.
#6

[eluser]sehummel[/eluser]
Problem solved. But I had to do this:

Options +FollowSymLinks
Options -Indexes
DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|images|css|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
#7

[eluser]Madmartigan1[/eluser]
It's from the manual - hence, "A little copy/paste from the manual".

Where are you getting a 404? Default controller?

Also FWIW, search the forums. There are already tons of posts about this very issue.

EDIT: I see you solved it. Thanks for sharing the code so others may benefit from it Smile
#8

[eluser]sehummel[/eluser]
See my comment above. I found this .htaccess here: http://ellislab.com/forums/viewthread/83332/
#9

[eluser]Madmartigan1[/eluser]
<3 .htaccess Smile

Just a warning, you may need to tweak for different servers.

Good luck!
#10

[eluser]noCodeMonkeys[/eluser]
Is there anyway to accomplish the same thing on a Windows server (iis) that does not use an .htaccess file?




Theme © iAndrew 2016 - Forum software by © MyBB