PHP code example of spanitz / silex-restful-controller

1. Go to this page and download the library: Download spanitz/silex-restful-controller library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

spanitz / silex-restful-controller example snippets




use spanitz\Silex\Provider\RestfulControllerProvider;

$app = new Silex\Application();
$app->mount('/api', new RestfulControllerProvider());


namespace Api\Controller;

use spanitz\Silex\RestfulController;

class Todo extends RestfulController
{
    public function get ($id = null)
    {
        $data = array();
        // fetch multiple todos, or a single one by its $id...

        return $data;
    }

    public function put ($id = null)
    {
        // update todo...
    }

    public function post ()
    {
        // create todo...
    }

    public function delete ($id = null)
    {
        // delete todo...
    }
}

 $app->mount('/api', new RestfulControllerProvider(array(
    'namespace' => 'My\Controller\Namespace'
 )));
 

 $app->mount('/api', new RestfulControllerProvider(array(
    'status-codes' => array(
        'post' => 200
        'put' => 200
    )
 )));