组织你的控制器到子目录CodeIgniter


Organizing Your Controllers into Sub-directories CodeIgniter

我想在codeigniter中创建我的网站的adminpanel,我想在单独的文件夹中管理adminpanel的控制器。我在controllers中创建了一个名为admin的文件夹,在controllers/admin.

中创建了一个名为Home.php的控制器。

现在,当我尝试使用http://localhost/web/admin/home/

显示404错误。

我还添加了$route["admin"] = "admin/home";

我做错了什么?

编辑:

MY .htaccess FILE

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /Azuaj
RewriteCond $1 !^(index'.php|library|user_guide|robots'.txt)
#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]
#When your application folder isn't in the system folder
#This snippet prevents user access to the application folder
#Submitted by: Fabdrol
#Rename 'application' to your applications folder name.
RewriteCond %{REQUEST_URI} ^application.*
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 $1 !^(index'.php|public|'.txt)
RewriteCond $1 !^(index'.php|library|user_guide|robots'.txt)
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>

添加到你的。htaccess文件

RewriteEngine On
RewriteBase /project/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]

我知道您的问题已经通过.htaccess解决了,但是您可能会发现您可以通过扩展来实现您的目标。

https://github.com/ollierattue/codeigniter-multi-level-controller-extension