【问题标题】:codeigniter controllers not workingcodeigniter 控制器不工作
【发布时间】:2015-02-08 13:47:25
【问题描述】:

我是 web 开发新手,所以这个问题可能很简单。

我已安装并运行 xampp,并且正在使用 netbeans 最新版本。

我目前正在尝试学习一个需要我制作几个控制器的教程,但我可以成功加载的唯一页面是 index.php。

我在 application/controllers 文件夹中创建了一个新控制器:

<?php
class Blog extends CI_Controller {
    public function index()
    {
        echo 'Say something';
    }
}
?>

并尝试通过

访问它
http://localhost/Something/Blog

但我得到一个错误:

Object not found!
The requested URL was not found on this server. If you entered the URL manually please check your spelling and try again.
If you think this is a server error, please contact the webmaster.
Error 404
localhost
Apache/2.4.10 (Win32) OpenSSL/1.0.1i PHP/5.6.3 

附言

http://localhost/Something is loading fine.

我已经编辑了 .htaccess 文件:

RewriteEngine on
RewriteCond %(REQUEST_FILENAME) !-f
RewriteCond %(REQUEST_FILENAME) !-d
RewriteRule ." index.php/$0 [PT,L]

我已经在谷歌上搜索了 3 个小时的解决方案,如果有任何帮助,我将不胜感激 :)

【问题讨论】:

标签: php codeigniter controller


【解决方案1】:

将 .htaccess 文件更改为:

RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]

另外,请尝试使用:

http://localhost/Something/index.php/Blog

【讨论】:

    【解决方案2】:

    试试这个:

    localhost/Something/index.php/controllername

    【讨论】:

      【解决方案3】:

      同时在浏览器 url 中写下 controller class 和 method 的名称。您可以使用:

      http://localhost/index.php/something/blog
      

      【讨论】:

        【解决方案4】:

        添加 htaccess 这段代码我的帮助

         RewriteEngine on
        RewriteCond %{REQUEST_URI} ^system.*
        RewriteRule ^(.*)$ /index.php/$1 [L]
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule ^(.*)$ index.php/$1 [L]
        

        【讨论】:

          猜你喜欢
          • 2017-05-29
          • 1970-01-01
          • 1970-01-01
          • 2012-02-24
          • 2019-03-21
          • 1970-01-01
          • 2017-11-01
          • 1970-01-01
          • 2023-03-06
          相关资源
          最近更新 更多