Hello every body i’ve a problem .
look here :
http://api.widesix.be
In theory i have this : {“result”:0,“test”:“super test”}
In reality i have this : {“result”:0,“test”:"s
In my local server if i turned of output_buffering off , the problem is resolved, but in production on a webserver where i don’t have acces to php.Ini i can’t turn off …
I try this
$api = new \Slim\App([‘settings’ => [‘outputBuffering’ => false]]);
But still not working… so what can i do ??
Thank
Can you show some code? Would help finding the problem.
Of course :
header(‘Access-Control-Allow-Origin: *’);
require ‘vendor/autoload.php’;
require ‘includes/token.php’;
require ‘includes/database.php’;
require ‘includes/methodes.php’;
//On genere une instance de slim.
$api = new \Slim\App([‘settings’ => [‘outputBuffering’ => false]]);
$cors = new \CorsSlim\CorsSlim();
$api->add($cors);
$api->get(’/’,‘HomeFct’);
$api->get(’/news’,‘GetNewsFct’);
$api->get(’/events’,‘GetEventsFct’);
$api->get(’/phpinfo’,‘GetPhpInfo’);
$api->get(’/authentification/{identifiant}/{motdepasse}’,‘AuthFct’);
$api->run();’
for example my method getNewsFct
function GetNewsFct(Request $request,Response $reponse){
$retour = array("result"=>0);
$list = array();
$sql = " SELECT news_id,news_date,news_titlefr,news_titlenl,news_contentfr,news_contentnl
FROM news
ORDER BY news_date LIMIT 5,20";
try {
$id=42;
$db = getDb();
$req = $db->prepare($sql);
//$req->bindParam("id",$id,PDO::PARAM_INT);
$req->execute();
$result=$req->fetchAll();
foreach($result as $k=>$v){
$list[] = array( "new_id" => $v['news_id'],
"date" => $v['news_date'],
"titlefr" => $v['news_titlefr'],
"text" => $v['news_contentfr'],
);
}
$retour = json_encode($list);
$db = null;
} catch(PDOException $e) {
$retour ='{"error":{"text":'. $e->getMessage() .'}}';
}
$reponse->getBody()->write($retour);
return $reponse;
}
I’ve write a method
function RenderFct($retour){
ob_start();
echo $retour;
$retour = ob_get_clean();
echo $retour;
ob_flush();
}
With that, all it’s good, but is it a good pratice??
Same questions with CORS MiddleWare which not work and i write the header manually and that’s good… but again why ? and it’s a good pratice?
Thank for your help
Somewhere you have some blank spaces before an opening <?php
tag.
Oki first problem is resolved , thank