slim
Slim 3 – how to get all get/ put/ post variables?
Get all get/put/post parameters: //GET $allGetVars = $request->getQueryParams(); foreach($allGetVars as $key => $param){ //GET parameters list } //POST or PUT $allPostPutVars = $request->getParsedBody(); foreach($allPostPutVars as $key => $param){ //POST or PUT parameters list } Single parameters value: //Single GET parameter $getParam = $allGetVars[‘title’]; //Single POST/PUT parameter $postParam = $allPostPutVars[‘postParam’];
Slim Framework for beginners [closed]
UPDATE: After 3 years, It is time to add some updates to this answer. A lot has changed in slim framework (and even PHP) during this time. Slim version 3 has been released and brought some major changes to it. In my tests, It is slightly slower and tad more complicated than slim 2, But … Read more
Axios – How to read JSON response?
In Axios responses are already served as javascript object, no need to parse, simply get response and access data.
Slim PHP and GET Parameters
You can do this very easily within the Slim framework, you can use: $paramValue = $app->request()->params(‘paramName’); $app here is a Slim instance. Or if you want to be more specific //GET parameter $paramValue = $app->request()->get(‘paramName’); //POST parameter $paramValue = $app->request()->post(‘paramName’); You would use it like so in a specific route $app->get(‘/route’, function () use ($app) … Read more
enable cors in .htaccess
Since I had everything being forwarded to index.php anyway I thought I would try setting the headers in PHP instead of the .htaccess file and it worked! YAY! Here’s what I added to index.php for anyone else having this problem. // Allow from any origin if (isset($_SERVER[‘HTTP_ORIGIN’])) { // should do a check here to … Read more