简体   繁体   中英

codeigniter Rest_controller output bad format

Whatever the output format selected some "\\r\\r\\r" appears at the beginning of output. With XML format, it generates a bad format error because <?xml is not the first chars. Looks like the "\\r" has been sended before the response directive and :

  $this->response($liste, 200); // 200 being the HTTP response code 

a die("test") before the parent::__construct(); is ok but after I receive "\\r\\r\\rtest" so something in Rest_controller output the \\r???

All the restfull API is working perfectly except that issue. thank you for your precious help

I have found the reason. It comes from the CI_Controller when loading the librairies : you must avoid to close PHP at the end of all librairies and includes like that :

  • } /* End of file module_xxx.php / / Location: ./application/librairies/module_xx/module_xxx.php */

I have found the reason. It comes from the CI_Controller when loading the librairies : you must avoid to close PHP at the end of all librairies and includes like that :

<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
    class Module_xxx extends Module_yyy {

-
    }
/* End of file module_xxx.php */
/* Location: ./application/librairies/module_xx/module_client.php */

Codeigniter loader loads the librairies with includes statements and send at that time all relevant lines after the PHP closure (in fact this is PHP involved). Best way would be to avoid PHP closure in all files.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM