将控制器组织到子目录CodeIgniter

时间:2015-09-15 12:42:21

标签: php codeigniter controller

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

现在,当我尝试使用时访问此控制器 http://localhost/web/admin/home/

它给我404错误。

我还添加了$ route [" admin"] =" admin / home&#34 ;;在routes.php文件中。

我做错了什么?

修改 我的.htaccess文件

<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>

2 个答案:

答案 0 :(得分:1)

在.htaccess文件中添加此内容

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

这应该对你有帮助..

答案 1 :(得分:0)

我知道您的问题已经通过.htaccess解决了,但您可能会感到有趣,因为您可以通过扩展来实现目标。

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