Reputation: 446
I've made a website using codeigniter framework it's work perfect on my localhost, however didn't work on Linux server , I've made changes to baseurl , database , .htaccess and I've removed index.php perfectly ! but log file show this error when I try to access my url
PHP Parse error: syntax error, unexpected T_FUNCTION in /home/httpd/vhosts/Domain.com/httpdocs/application/libraries/format.php on line 231
I tried to make simple controller to echo"Hello" when I call function test ,
<?php
class test extends CI_Controller {
function __construct() {
parent::__construct();
echo "here";
}
function test(){
echo "Hello inside the function";
}
}
and the answer is
> here
404 Page Not Found
The page you requested was not found.
there's no function access :/
but when I make this:
<?php
class test extends CI_Controller {
function test(){
echo "Hello inside the function";
}
}
the answer will be
Hello inside the function
404 Page Not Found
The page you requested was not found.
there's function access :3
anyone can help ??!
btw this is my .htaccess code
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
Upvotes: 0
Views: 2116
Reputation: 5507
This is an answer regarding your "TEST" and not your initial question.
The short answer is you cannot have a method that has the same name as the controller. It will be looking for a method called index, which you don't have and hence the error.
I've written some test code based upon what you had...
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 */
The results. (CI 2.2.0)
If you use localhost/test you will get
Hello from the Constructor
Hello from the Index Function
Note: Without the index method I get the same error you are seeing.
If you use localhost/test/index you will get
Hello from the Constructor
Hello from the Index Function
If you use localhost/test/test you will get
Hello from the Constructor
Hello from the Index Function
Now you do not have an index method. If you see what happens above you will notice that using localhost/test/ Or localhost/test/test, it is looking for the default index method. And the test method isn't reachable as it has the same name as the controller.
Upvotes: 1