PHP code example of mixerapi / crud

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

    

mixerapi / crud example snippets


# src/Application.php
public function bootstrap(): void
{
    $this->addPlugin('MixerApi/Crud');
}

use MixerApi\Crud\Interfaces\{CreateInterface, ReadInterface, UpdateInterface, DeleteInterface, SearchInterface};

public function add(CreateInterface $create)
{
    $this->set('data', $create->save($this));
}

return $create->save($this, [
    'accessibleFields' => [
        'password' => true,
    ]
]);

public function view(ReadInteface $read)
{
    $this->set('data', $read->read($this));
}

return $read->save($this, ['contains' => ['OtherTable']]);

$query = $read->query($this)

public function edit(UpdateInterface $update)
{
    $this->set('data', $update->save($this));
}

return $update->save($this, [
    'accessibleFields' => [
        'password' => true,
    ]
]);

public function delete(DeleteInterface $delete)
{
    return $delete->delete($this)->respond(); // calling respond() is optional
}

return $delete->delete($this, ['atomic' => false]);

public function index(SearchInterface $search)
{
    $this->set('data', $search->search($this));
}

$this->set('data', $search->search($this));

$this->set('data', $search->setCollection('collection_name')->search($this));

$query = $search->query($this);

# src/Application.php

public function bootstrap(): void
{
    $this->addPlugin('MixerApi/Crud', $options);
}

$options = [
    'allowedMethods' => [
        'add' => ['post'],
        'edit' => ['patch'],
        'delete' => ['delete'],
    ]
];

$options = [
    'allowedMethods' => []
];

$options = [
    'doSerialize' => false, // default is true
];

public function view(ReadInteface $read, string $id)
{
    $this->set('data', $read->read($this, $id));
}