PHP code example of adrotec / webapi-bundle

1. Go to this page and download the library: Download adrotec/webapi-bundle 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/ */

    

adrotec / webapi-bundle example snippets



// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...
        new JMS\SerializerBundle\JMSSerializerBundle(),
        new Adrotec\WebApiBundle\AdrotecWebApiBundle(),
        // ...
    );
}


// src/EmpDirectory/Bundle/Controller/ApiController.php

namespace EmpDirectory\Bundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;

class ApiController extends Controller
{

    public function apiAction(Request $request)
    {
        $api = $this->container->get('adrotec_webapi');

        $api->addResources(array(
            'Employees' => 'EmpDirectory\Bundle\Entity\Employee',
            'Departments' => 'EmpDirectory\Bundle\Entity\Department',
            'Jobs' => 'EmpDirectory\Bundle\Entity\Job',
        ));
        
        // $request->attributes->set($request->attributes->get('resource'));

        $response = $api->handle($request);
        
        return $response;
    }

}