This is the RESTAdapter code as in the Ember js guide:
App.ApplicationAdapter = DS.RESTAdapter.extend({
namespace: 'emberboot/api',
headers: {
'API_KEY': 'secret key'
}
});
This is the code for getting headers from SLIM PHP. The get headers function is documented here http://docs.slimframework.com/#Request-Headers
// - http://localhost/emberboot/api/posts
// - $app->get('/posts', 'getPosts'); //get all post
function getPosts()
{
$request = \Slim\Slim::getInstance()->request();
$key = $request->headers->get('API_KEY');
//logging
$file = 'headers.txt';
file_put_contents($file, $key);
;
;
This is from the Chrome Developer Tool:
Clearly there is nothing wrong from the Ember-data part coz the header is there. However THE LOGGING FILE: headers.txt contain no text at all - empty!
UDATED - ANSWERS AS SOLVE BY @engvrdr. Use dash instead of underscore
This is the RESTAdapter code UPDATED!
App.ApplicationAdapter = DS.RESTAdapter.extend({
namespace: 'emberboot/api',
headers: {
'API-KEY': 'secret key'
}
});
The Slim PHP code updated:
function getPosts()
{
$request = \Slim\Slim::getInstance()->request();
$headers = $request->headers;
$apiKey = $headers->get('API-KEY');
$file = 'headers.txt';
file_put_contents($file, $apiKey);
;
;