Jump to content

JSON service for back end


common

Recommended Posts

Hi everyone.

 

I am looking at creating my application's back end with PHP, which returns all data with Jason or simplexml. I have tried Slim once, but think there should be something easier to use.

 

Can anyone give me suggestions on what I can use which is easy to catch on, and maybe an example?

 

Appreciate it.

 

Kind regards

Link to comment
https://forums.phpfreaks.com/topic/289749-json-service-for-back-end/
Share on other sites

Hi

 

Thanks for your reply.

 

I tried looking at the website, but had some difficulty to understanding/initialize the Slim app object. So I am

not sure if I am doing it correctly now:

 

Can you maybe just help me where I go wrong, or what developing pattern I should follow. Here is something I have already.

<?php
header("Content-Type: application/json");

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

$app = new \Slim\Slim();
$app->get('/users', 'findAll');
$app->get('/users/:id', 'findById');
$app->post('/user/new', 'create');
$app->put('/user/update', 'update');
$app->run();


function create() {
     $app = new \Slim\Slim();
     $request = $app->request; //Slim::getInstance()->request();

     $user->json_decode($request->getBody(),true);

     $id = ....
     echo $id;
}


function update() {
    $request = Slim::getInstance()->request();
    $user = json_decode($request->getBody());
    ...
}

function findAll() {
    $userarr =...
    echo json_encode($userarr);
}


function findById($id) {
    $user = ...
    echo json_encode($user); 
}

?>

Thanks in advance.

  • 2 weeks later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.