Welcome Guest, Not a member yet? Register   Sign In
Subfolder organization
#1

[eluser]rolandpish[/eluser]
Hello.
I'm in the first time using codeigniter.
I installed it in: http://localhost/codeigniter

I need to develop a site with a public access area and an administration area, so I created an "admin" folder under application/controllers folder, and created an "admin" folder under application/views folder as well.

Then as a test, I created a sample controller (login.php) under controllers/admin folder with the following code:
Code:
<?php

class Login extends Controller {

    function Login()
    {
        parent::Controller();
    }

    function index()
    {
        $data['title'] = 'Administration Area';
        $data['message'] = 'You are in the admin login page';
        $this->load->view('admin/login',$data);
    }
}
and I created a sample view (login.php) under views/admin folder with the code:
Code:
<html>

<head>
    <title><?=$title?></title>
</head>

<body>
    <h1>&lt;?=$message?&gt;</h1>
&lt;/body&gt;

&lt;/html&gt;
After that I added
Quote:$route['admin'] = 'admin/login';
in routes.php file.

I have tried pointing to:
http://localhost/codeigniter/admin
http://localhost/codeigniter/admin/login
but got a 404 error.

As I pointed, I'm a newbie with codeigniter. What am I doing wrong?

Thanks in advance
#2

[eluser]pistolPete[/eluser]
Do you use a .htaccess file? Did you set RewriteBase correctly?
#3

[eluser]rolandpish[/eluser]
Yes, this is the .htaccess file I put inside http://localhost/codeigniter folder:
Code:
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    #Removes access to the system folder by users.
    #Additionally this will allow you to create a System.php controller,
    #previously this would not have been possible.
    #'system' can be replaced if you have renamed your system folder.
    RewriteCond %{REQUEST_URI} ^system.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]

    #Checks to see if the user is attempting to access a valid file,
    #such as an image or css document, if this isn't true it sends the
    #request to index.php
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

<IfModule !mod_rewrite.c>
    # If we don't have mod_rewrite installed, all 404's
    # can be sent to index.php, and everything works as normal.
    # Submitted by: ElliotHaughin

    ErrorDocument 404 /index.php
</IfModule>
#4

[eluser]pistolPete[/eluser]
I guess you need to set
Code:
RewriteBase /codeigniter
#5

[eluser]rolandpish[/eluser]
I changed that, but it's not working, it keeps showing:

The requested URL /codeigniter/admin was not found on this server.
#6

[eluser]rolandpish[/eluser]
Update: I removed the .htaccess file, reconfigured config.php file and it worked.
Something is wrong with my .htaccess.
#7

[eluser]rolandpish[/eluser]
Well, first I want to say I'm sorry for my stupidity because I realized I didn't have the "AllowOverride FileInfo" directive on my document root apache configuration, so the .htaccess file wasn't doing anything.
Now everything works like a charm.

Sorry and thanks a lot!




Theme © iAndrew 2016 - Forum software by © MyBB