我使用codeigniter框架创建了一个网站,它在我的localhost上工作得很好,但是在Linux服务器上没有用, 我已经对baseurl,数据库,.htaccess进行了更改 我完全删除了index.php! 但是当我尝试访问我的URL时,日志文件显示此错误
PHP Parse错误:语法错误,意外的T_FUNCTION /home/httpd/vhosts/Domain.com/httpdocs/application/libraries/format.php 在第231行
当我调用函数test时,我试图让简单的控制器回显“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]
答案 0 :(得分:1)
这是关于你的“测试”的答案,而不是你最初的问题。
简短的回答是你不能拥有一个与控制器同名的方法。它将寻找一个名为index的方法,你没有它,因此也就是错误。
我根据你所拥有的内容编写了一些测试代码......
for(i = 0; i < 8; i++)
{
for(j = 0; j < 10; j++)
{
System.out.print(twoarray[i][j]);
}
}
结果。 (CI 2.2.0)
如果您使用localhost / test,您将获得
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 */
注意:如果没有索引方法,我会看到相同的错误。
如果您使用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 ,它正在寻找默认的索引方法。并且无法访问测试方法,因为它与控制器具有相同的名称。