PHP code example of meksiabdou / ci4-restful

1. Go to this page and download the library: Download meksiabdou/ci4-restful 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/ */

    

meksiabdou / ci4-restful example snippets



use CI4Restful\Helpers\RestServer;

class ApiController extends RestServer
{
    public function index()
    {
        return $this->response_json(["id" => 1, "bar" => "foo" ]], true);
    }
}

public function store($requestData=null) {

    $this->db->insert('mytable', $requestData);
    $id = $this->db->insert_id();
    
    return $this->response->json(['id'=>$id], true , 201);
}


public function store($requestData=null) {

    if(!$requestData) {
        return $this->response->json([], false );
    }
    
}


public $aliases = [
    'cors' => \Fluent\Cors\Filters\CorsFilter::class,
    // ...
];

public filters = [
    // ...
    'cors' => ['after' => ['api/*']],
];

class App extends BaseConfig {

	public $token_app = ['2ve7Wq9P2QLnzQMlN2uVnBfb10xvOY0NQTuQ7Q'];

   //...

class Store extends RestServer {}