Adam Skiba
Adam Skiba

Reputation: 633

CodeIgniter new controller not found?

I installed latest CodeIgniter and copied welcome.php to backend.php, and changed the class variable to Backend however when I go to /backend it says controller not found. The contents of my .htaccess are as follows.

# Do not remove this line, otherwise mod_rewrite rules will stop working
RewriteBase /
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [QSA,L]

I also tried to change the uri method to request uri, still the same issue.

The index controller works, but not the backend which was created from the index. (welcome.php)

Upvotes: 0

Views: 6484

Answers (2)

prat1kk
prat1kk

Reputation: 416

YOu will need a htaccess file that has the following written in it.

<IfModule mod_rewrite.c>
RewriteEngine on


RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

The problem is that the controller can be accessed by adding /index in the URL and then the controller name.

Therefore, you need a htaccess file to remove that issue.

Upvotes: 1

Stelian Matei
Stelian Matei

Reputation: 11623

Check if the class name defined in backend.php is Backend:

class Backend extends CI_Controller { ... }

Make sure you have a method index (default action) in the Backend controller:

 public function index() { ... }

PS: You could also create a new directory backend and put there ALL your controllers that you need in the backend. This would make things easier if you have complex functionality in the backend area.

Upvotes: 2

Related Questions