1
votes

I'm not really new with Codeigniter but have been working on started projects so far. Now I'm starting a new small project on my own and I'm kinda lost.

I downloaded codeigniter, configured all the parameters in wamp so I have this base URL: http://local.project

Now I'm trying to build a small admin. I should be able to enter to this admin through http://local.project/admin which should show a login page. I already have a template for this.

The thing is that same 404 error appears. The configuration I have is this:

Inside config folder, routes.php:

$route['default_controller'] = "admin";
$route['404_override'] = '';
$route['admin'] = 'admin';

then on controllers folder, created another folder admin with a file also called admin.php which contains:

<?php
  class Admin extends CI_Controller {
    public function index()
    {
    echo 'Hello World!';
    }
    }
?>

now, trying to access from the browser I've tried many possible url but I'm still not sure of how it should be>

http://local.project/admin

and other combinations like

http://local.project/admin/index.php http://local.project/index http://local.project/index/admin

but always appears error 404 page not found.

So I'm really wondering, what am I doing wrong?

EDIT

this is what .htaccess contains>

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule .* index.php/$0 [PT,L]
1
Look at your apache logs, and see whats going on in there. You may need to configure it to show redirects. Secondly make sure Rewrite is enabled, or it will never hit codeigniter's .htaccess file. - Chris
@Chris I've edited my post. htaccess I believe has rewrite enabled. What logs do you mean? - Limon
Oamm try without using the . (dot) in your base url, usually it's something like http://localhost/myproject/ or http://127.0.0.1/myproject/ also, are you sure apache it's running ? - Allende
@Allende I never had problems with the dot in other projects. Yes, apache is running - Limon
@Limon with local projects ? I think the browser will try to look for the domain "local.project" instead of using localhost, if you have had already used that in your localhost then you can skip it, if don't give it a try removing the . (dot) notation from your base_url - Allende

1 Answers

0
votes

You're perfectly reasonable to assume that by defining a default controller it should work in subfolders, but ellislabs doesn't agree. As per the user guide:

$route['default_controller'] = 'welcome';

This route indicates which controller class should be loaded if the URI contains no data, which will be the case when people load your root URL. In the above example, the "welcome" class would be loaded. You are encouraged to always have a default route otherwise a 404 page will appear by default.

The key words there are "if the URI contains no data." "/admin" contains data. If you put your Admin controller in the root controllers folder and put in "local.project/" you'd get the index function of the Admin controller, but in a subfolder, you have to specify the full path, which in this case would be "/admin/admin/index." Putting that into your "admin" route will fix the issue, and then adding another route to take care of any other functions ($route["admin/(:any)'] = 'admin/admin/$1' should do the trick) will fix the rest.

And just so you know, if you ever upload this code to a server running Linux, it'll break because "Admin" and "admin" are two different controllers as far as Linux/Unix are concerned. As a long-time Windows dev, I feel your pain on that one.