Krishna Sarma Krishna Sarma - 1 month ago 18
PHP Question

accessing controller in subfolder codeigniter

Just downloaded CI 2.2, renamed the folder to Test1, copied into htdocs folder of xampp.

Tested the site by accessing

http://localhost/Test1
, it launched the Welcome message. Now added a folder to controllers ("admin") and a controller in it (home.php). so the structure is:

controllers
--> admin
--> home.php
--> index.php
--> welcome.php


and the code in home.php is

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Home extends CI_Controller {
public function index()
{
echo 'Hello';
}
}


When I try accessing
http://localhost/Test1/admin/home
or
http://localhost/Test1/admin/home/index
it says object not found (404 error).

I also tried adding
$route['admin'] = "admin/home";
to
application\config\routes.php
so that I can access as
http://localhost/Test1/admin
but of no use. Am I missing a setting?

Answer

create a file htaccess.htaccess and past the following code in it. save it in your Test1 folder

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* /Test1/index.php/$0 [PT,L]