Naming convention issues when using codeigniter in windows and linux
As advised by Prix, I checked my error log and found that the problem was due to syntax error.
I was using Function array dereferencing which has been added in PHP 5.4.0 but my server was running PHP 5.2.
The solution is here
The solution worked. I had to resort to this method rather than upgrading my PHP version because the server is running UBUNTU 12.04 which has no repos for PHP 5.4 .
Codeigniter file names and loading helpers under Linux
I think you can wrap the function into the class
class MY_form_helper{
static function set_value($field = '', $default = '')
{
if (FALSE === ($OBJ =& _get_validation_object()))
{
if (isset($_POST[$field]))
{
return form_prep($_POST[$field], $field);
}
if (isset($_GET[$field]))
{
return form_prep($_GET[$field], $field);
}
return $default;
}
return form_prep($OBJ->set_value($field, $default), $field);
}
}
and you will be able to call it like:
MY_form_helper::set_value($field, $default);
or you need to use namespaces but this is longer
Error when moving project from Windows to Linux mod_fcgid: stderr: PHP Fatal error: Class 'Public_Controller' not found
Linux is case sensitive when it comes to file naming conventions. Double check the cases on your controllers. Specifically, make sure your file is called Public_Controller.php
Problem with Codeigniter and Doctrine, migrating from Windows to Linux server
found the solution here: http://www.misty-stix.com/codeigniter-doctrine-migration-from-windows-to-linux/
CodeIgniter returning 404 if controller files are in lowercase on linux
In Codeigniter 3 you have to create file names with caps in first. File names means Model and Controller.
And in Windows it will work when its in small capes. But in linux it will not. Its Case-Sensitive.
Naming Conventions in Codeigniter
CodeIgniter project not work on Linux-based remote server
On codeIgniter 3 + versions a couple of checks to do if getting errors below.
- error 404 page not found
- Unable to load the requested file
Check first.
- Make sure your file name has the first letter upper case only
- Make sure your class name has first letter upper case only
- This applies for models as well.
Warning: Some times even though lower case may work on some localhost some other operating systems it may cause error when file or class are lower case, it may not be the same for everyone.
Controller
File name: Home.php
<?php
class Home extends CI_Controller {
public function __construct() {
parent::__construct();
$this->load->model('model_example');
}
public function index(){
// $data['results'] = $this->model_example->get_results();
$this->load->view('home');
}
}
Folder Structure for View
application
application > views > home.php
Models
File name: Model_example.php
<?php
class Model_example extends CI_Model {
public function get_results() {
// Some Code Here.
}
}
On your config.php
$config['base_url'] = 'http://localhost/your_project_name/';
CodeIgniter Controller Case-Sensitive
As you said you are using CI 3.
Codeigniter change log says
Changed filenaming convention (class file names now must be Ucfirst
and everything else in lowercase). So you controllers and files name
should be
My_controller
(only M upper case rest lower case)Public_controller
Application_controller
Foo_controller
CI-2 was better in this case.
Codeigniter Class and filename case sensitive on Linux (centos)
Note 1:
Windows hosting and Linux hosting has difference in file names.(Also
Most of the Live Hosting providers (in server) will not give full freedom as working as localhost. There will be some strict modes and policies implemented in server for security reasons.)
Note 2:
The problem exist coz file name differs on Linux and Windows MyFile & myfile can not exist in a same path in Windows, but can on a Linux
codeigniter url case sensitive issue
Related Topics
How to Make Number_Format() Not to Round Numbers Up
Executing MySQLi_Query Inside a Function
How to Run PHP Files on My Computer
How to Put PHP Inside JavaScript
Is It Necessary to Declare PHP Array Before Adding Values with []
Is There Way to Keep Delimiter While Using PHP Explode or Other Similar Functions
Dynamic Class Method Invocation in PHP
Naming Convention Issues When Using Codeigniter in Windows and Linux
PHP Commands Out of Sync Error
Post Form and Update Multiple Rows with MySQL
PHP MySQL Update If Exist or Insert If Not
Laravel 5.2 $Errors Not Appearing in Blade