PHP code example of ahmedebead / cake-rest-api

1. Go to this page and download the library: Download ahmedebead/cake-rest-api 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/ */

    

ahmedebead / cake-rest-api example snippets



// src/Application.php


 public function bootstrap(): void
    {
        $this->addPlugin('CakeRestApi', ['bootstrap' => true]);
        
        // Other code
    }


$routes->connect('/foo/bar', ['controller' => 'Foo', 'action' => 'bar', 'isRest' => true]);



namespace App\Controller;

use CakeRestApi\Controller\RestController;

/**
 * Foo Controller
 *
 */
class FooController extends CakeRestApiController
{

    /**
     * bar method
     *
     * @return Response|void
     */
    public function bar()
    {
        $bar = [
            'falanu' => [
                'dhikanu',
                'tamburo'
            ]
        ];

        $this->set(compact('bar'));
    }
}