I experiment an odd things on codeigniter. Adding my own library, model, or config in the autoload breake my json response in ajax request.
The installation of CI is totally fresh. No url rewriting, nothing change inside the config.php
when i load like this my own component :
PHP Code:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
$autoload['packages'] = array();
$autoload['libraries'] = array('email');
$autoload['drivers'] = array();
$autoload['helper'] = array('user');
$autoload['config'] = array('google');
$autoload['language'] = array();
$autoload['model'] = array('user_model');
user_helper.php google.php and User_model.php contain strictly nothing
user_helper:
PHP Code:
<?php defined('BASEPATH') OR exit('No direct script access allowed');
if ( ! function_exists('user'))
{
function user() {}
}
User_model:
PHP Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class User_model extends CI_Model
{
public function user() {}
}
google:
PHP Code:
<?php defined('BASEPATH') OR exit('No direct script access allowed');
$config['lang'] = "fr";
like this we can't say it's my coding who put the mess.
and the ajax call looke like this :
Code:
$(document).ready(function() {
$.post(
"http://www.codeigniter.dev/index.php/ajaxrequest/test",
{
id: 'test'
},
function(data)
{
console.log(data);
},
"json"
);
});
the result looke like this
As you can see nothing appear with the console log and no response in json format.
If i replace the autoload with this :
PHP Code:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
$autoload['packages'] = array();
$autoload['libraries'] = array('email');
$autoload['drivers'] = array();
$autoload['helper'] = array();
$autoload['config'] = array();
$autoload['language'] = array();
$autoload['model'] = array();
and i load those missing file inside the controler like this :
PHP Code:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Test extends CI_Controller
{
public function index()
{
$this->load->helper(array('user'));
$this->load->model(array('user_model'));
$this->config->load('google');
$this->load->view('test_message');
}
}
Tadam it's magic :
the ajax and json respond normally.
I must add than when i autoload only one of my own file it's worke normally.
It is normal? CI can't autoload more than one of my file without breaking json response?
Like you can see i have done nothing inside the project for not polluate the error process.