【问题标题】:codeigniter not working on linuxcodeigniter 不能在 linux 上运行
【发布时间】:2015-07-18 18:17:47
【问题描述】:

我已经使用 codeigniter 框架创建了一个网站,它在我的本地主机上完美运行,但在 Linux 服务器上无法运行, 我对 baseurl 、 database 、 .htaccess 进行了更改 我已经完美地删除了 index.php ! 但是当我尝试访问我的网址时,日志文件会显示此错误

PHP 解析错误:语法错误,出现意外的 T_FUNCTION /home/httpd/vhosts/Domain.com/httpdocs/application/libraries/format.php 在第 231 行

我尝试制作简单的控制器在调用函数测试时回显“Hello”,

<?php
class test extends CI_Controller {
    function __construct() {
        parent::__construct();
        echo "here";
    }

    function test(){    
        echo "Hello inside the function";           
    }
}

答案是

> here 
404 Page Not Found
The page you requested was not found.

没有功能访问:/

但是当我做这个时:

<?php
class test extends CI_Controller {
    function test(){    
        echo "Hello inside the function";           
    }
}

答案是

Hello inside the function
404 Page Not Found
The page you requested was not found.

有函数访问:3

有人可以帮忙吗??!

顺便说一句,这是我的 .htaccess 代码

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

【问题讨论】:

  • 您是否查看了第 231 行的 /home/httpd/vhosts/Domain.com/httpdocs/application/libraries/format.php?这些错误消息是有原因的。
  • 是的,没有什么奇怪的array_walk_recursive($str, function(&amp;$item, $key),我以前多次使用过这个库:/没有任何问题
  • 您运行的是什么版本的 PHP?匿名函数是 5.3+。 5.4 之前的任何东西现在都是 EOL。
  • 不应该专门针对这种情况,但至少要遵循最低标准:1.) 库文件名应该大写Format.php, 2.) 类名应该大写class Test extends CI_Controller{} , 3.) 方法应该具有可见性public function test(){}。您将在未来避免潜在的头痛。顺便提一句。使用什么版本的 CI?
  • /application/libraries/format.php 未与 Code Igniter 2.2 绑定。使用 Code Igniter 2.2 并不意味着每个 3rd 方库都可以与您过时的 PHP 版本一起使用

标签: php linux apache .htaccess codeigniter


【解决方案1】:

这是关于您的“测试”的答案,而不是您最初的问题。

简短的回答是您不能拥有与控制器同名的方法。它将寻找一个名为 index 的方法,而您没有该方法,因此会出现错误。

我已经根据你的内容编写了一些测试代码......

class Test extends CI_Controller {

    public function __construct() {
        parent::__construct();
        echo 'Hello from the Constructor<br>';
    }

    public function index() {
        echo 'Hello from the Index Function<br>';
    }

    public function test() {
        echo 'Hello from the Test Function<br>';
    }
}
/* End of file test.php */
/* Location: ./application/controllers/test.php */

结果。 (CI 2.2.0)

如果你使用 localhost/test 你会得到

Hello from the Constructor
Hello from the Index Function

注意:如果没有 index 方法,我会遇到与您看到的相同的错误。

如果你使用 localhost/test/index 你会得到

Hello from the Constructor
Hello from the Index Function

如果你使用 localhost/test/test 你会得到

Hello from the Constructor
Hello from the Index Function

现在您没有索引方法。如果您看到上面发生的情况,您会注意到使用 localhost/test/localhost/test/test,它正在寻找默认的索引方法。并且无法访问测试方法,因为它与控制器同名。

【讨论】:

  • 感谢您的宝贵回答,我花了 10 多个小时才得到运行我的网站的任何解决方案:/,这促使我尝试任何简单的课程帮助我捕捉错误,我试过了你说什么,它运行得很好。
  • 我很高兴它有帮助:)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-05-22
  • 2014-01-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-04-10
  • 2020-04-02
相关资源
最近更新 更多