Jump to content

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...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.