Some of you might think that this question was already asked hundred of times, still I haven't found an answer to the specific problem I have.
I have read these topics but none of them answers the question I have:
https://github.com/bcit-ci/CodeIgniter/issues/1805
codeigniter upload not working on linux
Codeigniter web app is not working with the linux but here on windows is fine
Naming convention issues when using codeigniter in windows and linux
I am developing a PHP application. My test server at home runs Windows, the stage server runs Ubuntu (Amazon AWS).
My application worked flawlessly until I needed to create a helper:
MY_form_helper.php
In that helper I needed to overwrite this:
function set_value($field = '', $default = '') { if (FALSE === ($OBJ =& _get_validation_object())) { if ( ! isset($_POST[$field])) { return $default; } return form_prep($_POST[$field], $field); } return form_prep($OBJ->set_value($field, $default), $field); }
with this:
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); }
So I saved the changes to the
MY_form_helper.php
Tested it all on windows and great everything works. All you PHP gurus probably know what happens now, I upload to linux server and errors :)
First error I get this:
An Error Was Encountered
Unable to load the requested file: helpers/my_form_helper.php
Well ok, linux is case sensitive so I have changed all the upper case file names to the lower case ones. After doing that I was greeted by blank page.
Side note: I have libraries that have capitalised first letter in name (for example I use flexi_auth library) and it always worked on the server. I dont know why now, as surely it should have failed on the Linux because of the capital letters in file names - would be great if someone could explain.
I have changed config in my index.php to display all the errors by adding
ini_set('display_errors', 1);
here:
if (defined('ENVIRONMENT'))
{
switch (ENVIRONMENT)
{
case 'development':
error_reporting(E_ALL);
ini_set('display_errors', 1);
break;
case 'testing':
case 'production':
error_reporting(0);
break;
default:
exit('The application environment is not set correctly.');
}
}
I reload the page and now I can see that there is fatal error:
Fatal error: Cannot redeclare set_value() (previously declared in /var/www/html/stage/bik/system/helpers/form_helper.php:675) in /var/www/html/stage/bik/application/helpers/my_form_helper.php on line 5
And here is where I am stuck. I did a big no-no and edited the form_helper in the core system files of CI with my code. I needed it all to work as I have people testing the whole thing and I couldn't have them wait.
So could someone explain to me what is going on? I am relatively new to Linux having always used Windows machines and servers. But I want to go with the flow and use Linux as cool kids do.
- Here are few more bits that might help
MY_form_helper file:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
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);
}
This is how I load it in controller:
$this->load->helper('MY_form_helper');
I have changed both capital letter to lower case when moving it to linux server.
And now something that boggles my mind, I have created MY_Input library and I am loading it from core folder in CI Appliaction folder. This thing has upper case letters in name and it works on the Linux server.
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class MY_Input extends CI_Input {
function save_query($query_array){
$CI =& get_instance();
$CI->db->insert('ci_query', array('query_string' => http_build_query($query_array)));
return $CI->db->insert_id();
}
function load_query($query_id){
$CI =& get_instance();
$rows = $CI->db->get_where('ci_query', array('queryid' => $query_id))->result();
if (isset($rows[0])) {
parse_str($rows[0]->query_string, $_GET);
}
}
}
I am still learning PHP and I do not get many things and I do not have much experience so I really appreciate all the help anyone can give me.
I hope I made clear what I need answering. Thank you to whomever who is willing to share their knowledge with me!