Learn the powerful enterprise adaptable database:

Getting Started With ADABAS & Natural

Monday, January 1, 2018

Slim PHP Simple Setup


1) Download Package


slim.zip


2) Apache ModRewrite

the .htaccess contains the following code:

RewriteEngine On

# Some hosts may require you to use the `RewriteBase` directive.
# If you need to use the `RewriteBase` directive, it should be the
# absolute physical path to the directory that contains this htaccess file.
#
# RewriteBase /

Header add Access-Control-Allow-Origin "*"
Header add Access-Control-Allow-Headers "origin, x-requested-with, content-type"
Header add Access-Control-Allow-Methods "PUT, GET, POST, DELETE, OPTIONS"

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]


3) Get and Post Method test codes


the index contains the following code:

<?php

require 'Slim/Slim.php';
\Slim\Slim::registerAutoloader();

$app = new \Slim\Slim();

$app->get('/testget/:params+','testGet');
$app->post('/testpost','testPost');

$app->run();

function testGet($params){
   echo json_encode($params);
}

function testPost(){
   $app = \Slim\Slim::getInstance();
   $postvars = $app->request->post();
   echo json_encode($postvars);
}

?>






No comments:

Post a Comment